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