async def post(self, request, *args, **kwargs): errors = {} form = RegistrationForm(request) if form.validate(): username = form.username.data password = await crypto.hash_SHA512(form.password.data) # we need to create a new user try: user = await db_objects.create(Operator, username=username, password=password) user.last_login = datetime.datetime.utcnow() await db_objects.update( user) # update the last login time to be now # generate JWT token to be stored in a cookie access_token, output = await self.responses.get_access_token_output( request, { 'user_id': user.id, 'auth': 'cookie' }, self.config, self.instance) refresh_token = await self.instance.auth.generate_refresh_token( request, { 'user_id': user.id, 'auth': 'cookie' }) output.update( {self.config.refresh_token_name(): refresh_token}) # we want to make sure to store access/refresh token in JS before moving into the rest of the app template = env.get_template('register.html') content = template.render(links=await respect_pivot(links, request), form=form, errors=errors, access_token=access_token, refresh_token=refresh_token, config={}) resp = response.html(content) resp.cookies[ self.config.cookie_access_token_name()] = access_token resp.cookies[ self.config.cookie_access_token_name()]['httponly'] = True resp.cookies[ self.config.cookie_refresh_token_name()] = refresh_token resp.cookies[ self.config.cookie_refresh_token_name()]['httponly'] = True return resp except Exception as e: # failed to insert into database print(e) errors['validate_errors'] = "Username already exists" errors['username_errors'] = '<br>'.join(form.username.errors) errors['password_errors'] = '<br>'.join(form.password.errors) template = env.get_template('register.html') content = template.render(links=await respect_pivot(links, request), form=form, errors=errors, config={}) return response.html(content)
async def get(self, request, *args, **kwargs): errors = {} form = RegistrationForm(request) template = env.get_template('register.html') content = template.render(links=await respect_pivot(links, request), form=form, errors=errors, config={}, view_utc_time=False) return response.html(content)
async def post(self, request, *args, **kwargs): errors = {} form = RegistrationForm(request) if form.validate(): username = form.username.data password = await crypto.hash_SHA512(form.password.data) # we need to create a new user try: user = await db_objects.create(Operator, username=username, password=password) user.last_login = datetime.datetime.utcnow() await db_objects.update( user) # update the last login time to be now default_operation = await db_objects.get(Operation, name="default") # now add the new user to the default operation await db_objects.create(OperatorOperation, operator=user, operation=default_operation) # generate JWT token to be stored in a cookie access_token, output = await self.responses.get_access_token_output( request, {'user_id': user.id}, self.config, self.instance) refresh_token = await self.instance.auth.generate_refresh_token( request, {'user_id': user.id}) output.update( {self.config.refresh_token_name(): refresh_token}) resp = response.redirect("/") resp.cookies[ self.config.cookie_access_token_name()] = access_token resp.cookies[ self.config.cookie_access_token_name()]['httponly'] = True resp.cookies[ self.config.cookie_refresh_token_name()] = refresh_token resp.cookies[ self.config.cookie_refresh_token_name()]['httponly'] = True return resp except Exception as e: # failed to insert into database errors['validate_errors'] = "failed to create user: " + str(e) if form.csrf_token: errors['token_errors'] = '<br>'.join(form.csrf_token.errors) errors['username_errors'] = '<br>'.join(form.username.errors) errors['password_errors'] = '<br>'.join(form.password.errors) template = env.get_template('register.html') content = template.render(links=links, form=form, errors=errors) return response.html(content)
async def post(self, request, *args, **kwargs): errors = {} form = RegistrationForm(request) if form.validate(): username = form.username.data password = await crypto.hash_SHA512(form.password.data) # we need to create a new user try: user = await db_objects.create( Operator, username=username, password=password, admin=False, active=False ) query = await db_model.operation_query() operations = await db_objects.execute(query) for o in operations: await db_objects.create( db_model.OperationEventLog, operator=None, operation=o, message="New user {} created".format(user.username), ) await set_default_scripts(user) return response.redirect("/login?success=true") except Exception as e: # failed to insert into database print(e) form.username.errors = ["Failed to create user"] errors["username_errors"] = "<br>".join(form.username.errors) template = env.get_template("register.html") content = template.render( links=await respect_pivot(links, request), form=form, errors=errors, successful_creation=False, config={}, view_utc_time=False, http="https" if use_ssl else "http", ws="wss" if use_ssl else "ws", ) return response.html(content)
async def get(self, request, *args, **kwargs): errors = {} form = RegistrationForm(request) template = env.get_template("register.html") content = template.render( links=await respect_pivot(links, request), form=form, errors=errors, config={}, view_utc_time=False, http="https" if use_ssl else "http", ws="wss" if use_ssl else "ws", ) return response.html(content)
async def register(request): errors = {} form = RegistrationForm(request) if request.method == 'POST' and form.validate(): username = form.username.data password = await crypto.hash_SHA512(form.password.data) # we need to create a new user try: user = await db_objects.create(Operator, username=username, password=password) login_user = User(id=user.id, name=user.username) auth.login_user(request, login_user) return response.redirect("/") except: # failed to insert into database errors['validate_errors'] = "failed to create user" errors['token_errors'] = '<br>'.join(form.csrf_token.errors) errors['username_errors'] = '<br>'.join(form.username.errors) errors['password_errors'] = '<br>'.join(form.password.errors) template = env.get_template('register.html') content = template.render(links=links, form=form, errors=errors) return response.html(content)
async def get(self, request, *args, **kwargs): errors = {} form = RegistrationForm(request) template = env.get_template('register.html') content = template.render(links=links, form=form, errors=errors) return response.html(content)
async def post(self, request, *args, **kwargs): errors = {} form = RegistrationForm(request) if form.validate(): username = form.username.data password = await crypto.hash_SHA512(form.password.data) # we need to create a new user try: user = await db_objects.create(Operator, username=username, password=password) user.last_login = datetime.datetime.utcnow() await db_objects.update( user) # update the last login time to be now query = await db_model.operation_query() operations = await db_objects.execute(query) for o in operations: await db_objects.create( db_model.OperationEventLog, operator=user, operation=o, message="New user {} created".format(user.username)) code = open("./app/scripts/browser_scripts.json", 'r').read() code = js.loads(code) result = await import_browserscript_func( code, {"username": username}) #print(result) # generate JWT token to be stored in a cookie access_token, output = await self.responses.get_access_token_output( request, { 'user_id': user.id, 'auth': 'cookie' }, self.config, self.instance) refresh_token = await self.instance.auth.generate_refresh_token( request, { 'user_id': user.id, 'auth': 'cookie' }) output.update( {self.config.refresh_token_name(): refresh_token}) # we want to make sure to store access/refresh token in JS before moving into the rest of the app template = env.get_template('register.html') content = template.render(links=await respect_pivot(links, request), form=form, errors=errors, access_token=access_token, refresh_token=refresh_token, config={}, view_utc_time=False) resp = response.html(content) resp.cookies[ self.config.cookie_access_token_name()] = access_token resp.cookies[ self.config.cookie_access_token_name()]['httponly'] = True resp.cookies[ self.config.cookie_refresh_token_name()] = refresh_token resp.cookies[ self.config.cookie_refresh_token_name()]['httponly'] = True return resp except Exception as e: # failed to insert into database print(e) errors['validate_errors'] = "Username already exists" errors['username_errors'] = '<br>'.join(form.username.errors) errors['password_errors'] = '<br>'.join(form.password.errors) template = env.get_template('register.html') content = template.render(links=await respect_pivot(links, request), form=form, errors=errors, config={}, view_utc_time=False) return response.html(content)
async def post(self, request, *args, **kwargs): errors = {} form = RegistrationForm(request) if form.validate(): username = form.username.data password = await crypto.hash_SHA512(form.password.data) # we need to create a new user try: user = await db_objects.create(Operator, username=username, password=password) user.last_login = datetime.datetime.utcnow() await db_objects.update( user) # update the last login time to be now query = await db_model.operation_query() operations = await db_objects.execute(query) for o in operations: await db_objects.create( db_model.OperationEventLog, operator=user, operation=o, message="New user {} created".format(user.username), ) await set_default_scripts(user) # print(result) # generate JWT token to be stored in a cookie access_token, output = await self.responses.get_access_token_output( request, { "user_id": user.id, "auth": "cookie" }, self.config, self.instance, ) refresh_token = await self.instance.auth.generate_refresh_token( request, { "user_id": user.id, "auth": "cookie" }) output.update( {self.config.refresh_token_name(): refresh_token}) # we want to make sure to store access/refresh token in JS before moving into the rest of the app template = env.get_template("register.html") content = template.render( links=await respect_pivot(links, request), form=form, errors=errors, access_token=access_token, refresh_token=refresh_token, config={}, view_utc_time=False, http="https" if use_ssl else "http", ws="wss" if use_ssl else "ws", ) resp = response.html(content) resp.cookies[ self.config.cookie_access_token_name()] = access_token resp.cookies[ self.config.cookie_access_token_name()]["httponly"] = True resp.cookies[ self.config.cookie_refresh_token_name()] = refresh_token resp.cookies[ self.config.cookie_refresh_token_name()]["httponly"] = True return resp except Exception as e: # failed to insert into database print(e) form.username.errors = ["Username already exists"] errors["username_errors"] = "<br>".join(form.username.errors) template = env.get_template("register.html") content = template.render( links=await respect_pivot(links, request), form=form, errors=errors, config={}, view_utc_time=False, http="https" if use_ssl else "http", ws="wss" if use_ssl else "ws", ) return response.html(content)