feat(chalice): refactored signup
This commit is contained in:
parent
f789c91e17
commit
4b3e414024
10 changed files with 37 additions and 74 deletions
|
|
@ -1,7 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from decouple import config
|
|
||||||
|
|
||||||
import schemas
|
import schemas
|
||||||
from chalicelib.core import users, telemetry, tenants
|
from chalicelib.core import users, telemetry, tenants
|
||||||
from chalicelib.utils import captcha
|
from chalicelib.utils import captcha
|
||||||
|
|
@ -20,55 +18,41 @@ def create_step1(data: schemas.UserSignupSchema):
|
||||||
print(f"=====================> {email}")
|
print(f"=====================> {email}")
|
||||||
password = data.password
|
password = data.password
|
||||||
|
|
||||||
print("Verifying email validity")
|
|
||||||
if email is None or len(email) < 5:
|
if email is None or len(email) < 5:
|
||||||
errors.append("Invalid email address.")
|
errors.append("Invalid email address.")
|
||||||
else:
|
else:
|
||||||
print("Verifying email existance")
|
|
||||||
if users.email_exists(email):
|
if users.email_exists(email):
|
||||||
errors.append("Email address already in use.")
|
errors.append("Email address already in use.")
|
||||||
if users.get_deleted_user_by_email(email) is not None:
|
if users.get_deleted_user_by_email(email) is not None:
|
||||||
errors.append("Email address previously deleted.")
|
errors.append("Email address previously deleted.")
|
||||||
|
|
||||||
print("Verifying captcha")
|
|
||||||
if helper.allow_captcha() and not captcha.is_valid(data.g_recaptcha_response):
|
if helper.allow_captcha() and not captcha.is_valid(data.g_recaptcha_response):
|
||||||
errors.append("Invalid captcha.")
|
errors.append("Invalid captcha.")
|
||||||
|
|
||||||
print("Verifying password validity")
|
|
||||||
if len(password) < 6:
|
if len(password) < 6:
|
||||||
errors.append("Password is too short, it must be at least 6 characters long.")
|
errors.append("Password is too short, it must be at least 6 characters long.")
|
||||||
|
|
||||||
print("Verifying fullname validity")
|
|
||||||
fullname = data.fullname
|
fullname = data.fullname
|
||||||
if fullname is None or len(fullname) < 1 or not helper.is_alphabet_space_dash(fullname):
|
if fullname is None or len(fullname) < 1 or not helper.is_alphabet_space_dash(fullname):
|
||||||
errors.append("Invalid full name.")
|
errors.append("Invalid full name.")
|
||||||
|
|
||||||
print("Verifying company's name validity")
|
organization_name = data.organizationName
|
||||||
company_name = data.organizationName
|
if organization_name is None or len(organization_name) < 1:
|
||||||
if company_name is None or len(company_name) < 1:
|
errors.append("Invalid organization name.")
|
||||||
errors.append("invalid organization's name")
|
|
||||||
|
|
||||||
print("Verifying project's name validity")
|
|
||||||
project_name = data.projectName
|
|
||||||
if project_name is None or len(project_name) < 1:
|
|
||||||
project_name = "my first project"
|
|
||||||
|
|
||||||
if len(errors) > 0:
|
if len(errors) > 0:
|
||||||
print("==> error")
|
print(f"==> error for email:{data.email}, fullname:{data.fullname}, organizationName:{data.organizationName}")
|
||||||
print(errors)
|
print(errors)
|
||||||
return {"errors": errors}
|
return {"errors": errors}
|
||||||
print("No errors detected")
|
|
||||||
|
project_name = "my first project"
|
||||||
params = {
|
params = {
|
||||||
"email": email, "password": password,
|
"email": email, "password": password, "fullname": fullname, "projectName": project_name,
|
||||||
"fullname": fullname,
|
"data": json.dumps({"lastAnnouncementView": TimeUTC.now()}), "organizationName": organization_name
|
||||||
"projectName": project_name,
|
|
||||||
"data": json.dumps({"lastAnnouncementView": TimeUTC.now()}),
|
|
||||||
"organizationName": company_name
|
|
||||||
}
|
}
|
||||||
query = f"""\
|
query = f"""WITH t AS (
|
||||||
WITH t AS (
|
INSERT INTO public.tenants (name)
|
||||||
INSERT INTO public.tenants (name, version_number)
|
VALUES (%(organizationName)s)
|
||||||
VALUES (%(organizationName)s, (SELECT openreplay_version()))
|
|
||||||
RETURNING api_key
|
RETURNING api_key
|
||||||
),
|
),
|
||||||
u AS (
|
u AS (
|
||||||
|
|
@ -106,7 +90,7 @@ def create_step1(data: schemas.UserSignupSchema):
|
||||||
}
|
}
|
||||||
c = {
|
c = {
|
||||||
"tenantId": 1,
|
"tenantId": 1,
|
||||||
"name": company_name,
|
"name": organization_name,
|
||||||
"apiKey": api_key,
|
"apiKey": api_key,
|
||||||
"remainingTrial": 14,
|
"remainingTrial": 14,
|
||||||
"trialEnded": False,
|
"trialEnded": False,
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ def get_by_tenant_id(tenant_id):
|
||||||
api_key,
|
api_key,
|
||||||
created_at,
|
created_at,
|
||||||
'{license.EDITION}' AS edition,
|
'{license.EDITION}' AS edition,
|
||||||
version_number,
|
openreplay_version() AS version_number,
|
||||||
opt_out
|
opt_out
|
||||||
FROM public.tenants
|
FROM public.tenants
|
||||||
LIMIT 1;""",
|
LIMIT 1;""",
|
||||||
|
|
|
||||||
|
|
@ -4,25 +4,18 @@ import re
|
||||||
import string
|
import string
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
import requests
|
from decouple import config
|
||||||
|
|
||||||
import schemas
|
import schemas
|
||||||
from chalicelib.utils.TimeUTC import TimeUTC
|
from chalicelib.utils.TimeUTC import TimeUTC
|
||||||
|
|
||||||
local_prefix = 'local-'
|
|
||||||
from decouple import config
|
|
||||||
|
|
||||||
|
|
||||||
def get_version_number():
|
|
||||||
return config("version")
|
|
||||||
|
|
||||||
|
|
||||||
def get_stage_name():
|
def get_stage_name():
|
||||||
return "OpenReplay"
|
return "OpenReplay"
|
||||||
|
|
||||||
|
|
||||||
def generate_salt():
|
def random_string(length=36):
|
||||||
return "".join(random.choices(string.hexdigits, k=36))
|
return "".join(random.choices(string.hexdigits, k=length))
|
||||||
|
|
||||||
|
|
||||||
def list_to_camel_case(items, flatten=False):
|
def list_to_camel_case(items, flatten=False):
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ class UserLoginSchema(_Grecaptcha):
|
||||||
class UserSignupSchema(UserLoginSchema):
|
class UserSignupSchema(UserLoginSchema):
|
||||||
fullname: str = Field(...)
|
fullname: str = Field(...)
|
||||||
organizationName: str = Field(...)
|
organizationName: str = Field(...)
|
||||||
projectName: str = Field(default="my first project")
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
alias_generator = attribute_to_camel_case
|
alias_generator = attribute_to_camel_case
|
||||||
|
|
|
||||||
|
|
@ -19,55 +19,42 @@ def create_step1(data: schemas.UserSignupSchema):
|
||||||
print(f"=====================> {email}")
|
print(f"=====================> {email}")
|
||||||
password = data.password
|
password = data.password
|
||||||
|
|
||||||
print("Verifying email validity")
|
if email is None or len(email) < 5:
|
||||||
if email is None or len(email) < 5 or not helper.is_valid_email(email):
|
|
||||||
errors.append("Invalid email address.")
|
errors.append("Invalid email address.")
|
||||||
else:
|
else:
|
||||||
print("Verifying email existance")
|
|
||||||
if users.email_exists(email):
|
if users.email_exists(email):
|
||||||
errors.append("Email address already in use.")
|
errors.append("Email address already in use.")
|
||||||
if users.get_deleted_user_by_email(email) is not None:
|
if users.get_deleted_user_by_email(email) is not None:
|
||||||
errors.append("Email address previously deleted.")
|
errors.append("Email address previously deleted.")
|
||||||
|
|
||||||
print("Verifying captcha")
|
|
||||||
if helper.allow_captcha() and not captcha.is_valid(data.g_recaptcha_response):
|
if helper.allow_captcha() and not captcha.is_valid(data.g_recaptcha_response):
|
||||||
errors.append("Invalid captcha.")
|
errors.append("Invalid captcha.")
|
||||||
|
|
||||||
print("Verifying password validity")
|
|
||||||
if len(password) < 6:
|
if len(password) < 6:
|
||||||
errors.append("Password is too short, it must be at least 6 characters long.")
|
errors.append("Password is too short, it must be at least 6 characters long.")
|
||||||
|
|
||||||
print("Verifying fullname validity")
|
|
||||||
fullname = data.fullname
|
fullname = data.fullname
|
||||||
if fullname is None or len(fullname) < 1 or not helper.is_alphabet_space_dash(fullname):
|
if fullname is None or len(fullname) < 1 or not helper.is_alphabet_space_dash(fullname):
|
||||||
errors.append("Invalid full name.")
|
errors.append("Invalid full name.")
|
||||||
|
|
||||||
print("Verifying company's name validity")
|
organization_name = data.organizationName
|
||||||
company_name = data.organizationName
|
if organization_name is None or len(organization_name) < 1:
|
||||||
if company_name is None or len(company_name) < 1:
|
errors.append("Invalid organization name.")
|
||||||
errors.append("invalid organization's name")
|
|
||||||
|
|
||||||
print("Verifying project's name validity")
|
|
||||||
project_name = data.projectName
|
|
||||||
if project_name is None or len(project_name) < 1:
|
|
||||||
project_name = "my first project"
|
|
||||||
|
|
||||||
if len(errors) > 0:
|
if len(errors) > 0:
|
||||||
print("==> error")
|
print(f"==> error for email:{data.email}, fullname:{data.fullname}, organizationName:{data.organizationName}")
|
||||||
print(errors)
|
print(errors)
|
||||||
return {"errors": errors}
|
return {"errors": errors}
|
||||||
print("No errors detected")
|
|
||||||
print("Decomposed infos")
|
|
||||||
|
|
||||||
params = {"email": email, "password": password,
|
project_name = "my first project"
|
||||||
"fullname": fullname, "companyName": company_name,
|
params = {
|
||||||
"projectName": project_name,
|
"email": email, "password": password, "fullname": fullname, "projectName": project_name,
|
||||||
"data": json.dumps({"lastAnnouncementView": TimeUTC.now()}),
|
"data": json.dumps({"lastAnnouncementView": TimeUTC.now()}), "organizationName": organization_name,
|
||||||
"permissions": [p.value for p in schemas_ee.Permissions]}
|
"permissions": [p.value for p in schemas_ee.Permissions]
|
||||||
query = """\
|
}
|
||||||
WITH t AS (
|
query = """WITH t AS (
|
||||||
INSERT INTO public.tenants (name, version_number)
|
INSERT INTO public.tenants (name)
|
||||||
VALUES (%(companyName)s, (SELECT openreplay_version()))
|
VALUES (%(organizationName)s)
|
||||||
RETURNING tenant_id, api_key
|
RETURNING tenant_id, api_key
|
||||||
),
|
),
|
||||||
r AS (
|
r AS (
|
||||||
|
|
@ -111,7 +98,7 @@ def create_step1(data: schemas.UserSignupSchema):
|
||||||
}
|
}
|
||||||
c = {
|
c = {
|
||||||
"tenantId": 1,
|
"tenantId": 1,
|
||||||
"name": company_name,
|
"name": organization_name,
|
||||||
"apiKey": api_key,
|
"apiKey": api_key,
|
||||||
"remainingTrial": 14,
|
"remainingTrial": 14,
|
||||||
"trialEnded": False,
|
"trialEnded": False,
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ def get_by_tenant_key(tenant_key):
|
||||||
t.api_key,
|
t.api_key,
|
||||||
t.created_at,
|
t.created_at,
|
||||||
'{license.EDITION}' AS edition,
|
'{license.EDITION}' AS edition,
|
||||||
t.version_number,
|
openreplay_version() AS version_number,
|
||||||
t.opt_out
|
t.opt_out
|
||||||
FROM public.tenants AS t
|
FROM public.tenants AS t
|
||||||
WHERE t.tenant_key = %(tenant_key)s AND t.deleted_at ISNULL
|
WHERE t.tenant_key = %(tenant_key)s AND t.deleted_at ISNULL
|
||||||
|
|
@ -33,7 +33,7 @@ def get_by_tenant_id(tenant_id):
|
||||||
t.api_key,
|
t.api_key,
|
||||||
t.created_at,
|
t.created_at,
|
||||||
'{license.EDITION}' AS edition,
|
'{license.EDITION}' AS edition,
|
||||||
t.version_number,
|
openreplay_version() AS version_number,
|
||||||
t.opt_out,
|
t.opt_out,
|
||||||
t.tenant_key
|
t.tenant_key
|
||||||
FROM public.tenants AS t
|
FROM public.tenants AS t
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ SELECT 'v1.8.2-ee'
|
||||||
$$ LANGUAGE sql IMMUTABLE;
|
$$ LANGUAGE sql IMMUTABLE;
|
||||||
|
|
||||||
ALTER TABLE IF EXISTS public.tenants
|
ALTER TABLE IF EXISTS public.tenants
|
||||||
ADD COLUMN IF NOT EXISTS last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT);
|
ADD COLUMN IF NOT EXISTS last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT),
|
||||||
|
DROP COLUMN IF EXISTS version_number;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS sessions_notes
|
CREATE TABLE IF NOT EXISTS sessions_notes
|
||||||
(
|
(
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,6 @@ $$
|
||||||
api_key text UNIQUE default generate_api_key(20) not null,
|
api_key text UNIQUE default generate_api_key(20) not null,
|
||||||
created_at timestamp without time zone NOT NULL DEFAULT (now() at time zone 'utc'),
|
created_at timestamp without time zone NOT NULL DEFAULT (now() at time zone 'utc'),
|
||||||
deleted_at timestamp without time zone NULL DEFAULT NULL,
|
deleted_at timestamp without time zone NULL DEFAULT NULL,
|
||||||
version_number text NOT NULL,
|
|
||||||
license text NULL,
|
license text NULL,
|
||||||
opt_out bool NOT NULL DEFAULT FALSE,
|
opt_out bool NOT NULL DEFAULT FALSE,
|
||||||
t_projects integer NOT NULL DEFAULT 1,
|
t_projects integer NOT NULL DEFAULT 1,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ SELECT 'v1.8.2'
|
||||||
$$ LANGUAGE sql IMMUTABLE;
|
$$ LANGUAGE sql IMMUTABLE;
|
||||||
|
|
||||||
ALTER TABLE IF EXISTS public.tenants
|
ALTER TABLE IF EXISTS public.tenants
|
||||||
ADD COLUMN IF NOT EXISTS last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT);
|
ADD COLUMN IF NOT EXISTS last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT),
|
||||||
|
DROP COLUMN IF EXISTS version_number;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS sessions_notes
|
CREATE TABLE IF NOT EXISTS sessions_notes
|
||||||
(
|
(
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,6 @@ $$
|
||||||
name text NOT NULL,
|
name text NOT NULL,
|
||||||
api_key text NOT NULL DEFAULT generate_api_key(20),
|
api_key text NOT NULL DEFAULT generate_api_key(20),
|
||||||
created_at timestamp without time zone NOT NULL DEFAULT (now() at time zone 'utc'),
|
created_at timestamp without time zone NOT NULL DEFAULT (now() at time zone 'utc'),
|
||||||
version_number text NOT NULL,
|
|
||||||
license text NULL,
|
license text NULL,
|
||||||
opt_out bool NOT NULL DEFAULT FALSE,
|
opt_out bool NOT NULL DEFAULT FALSE,
|
||||||
t_projects integer NOT NULL DEFAULT 1,
|
t_projects integer NOT NULL DEFAULT 1,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue