def login_post(): data = request_dict.create(default_val='') email = data.email.lower().strip() password = data.password.strip() if not email or not password: return { 'email': email, 'password': password, 'error': "Some required fields are missing.", 'user_id': cookie_auth.get_user_id_via_auth_cookie(flask.request), } user = user_service.login_user(email, password) if not user: return { 'email': email, 'password': password, 'error': "The account does not exist or the password is wrong.", 'user_id': cookie_auth.get_user_id_via_auth_cookie(flask.request), } resp = flask.redirect('/account') cookie_auth.set_auth(resp, user.id) return resp
def login_post(): # TODO: create view model for login data = request_dict.create() r = flask.request email = data.email.lower().strip() password = data.password.strip() if not email or not password: return { 'email': email, 'password': password, 'error': "Some require fields are missing", } user = user_service.login_user(email, password) if not user: return { 'email': email, 'password': password, 'error': "The account does not exist or the password is wrong", } resp = flask.redirect('/account') cookie_auth.set_auth(resp, user.id) return resp
def login_post(): data = request_dict.create(default_val='') email = data.email.lower().strip() password = data.password.strip() if not email or not password: return { 'email': email, 'password': password, 'error': "Some required fields are missing" } # TODO: Validate the user user = user_service.login_user(email, password) if not user: return { 'email': email, 'password': password, 'error': "The account does not exist or the password is incorrect" } resp = flask.redirect(url_for('account.index')) cookie_auth.set_auth(resp, user.id) return resp
def register_post(): data = request_dict.create(default_val='') name = data.name email = data.email.lower().strip() password = data.password.strip() if not name or not email or not password: return { 'name': name, 'email': email, 'password': password, 'error': "Some required fields are missing.", 'user_id': cookie_auth.get_user_id_via_auth_cookie(flask.request), } user = user_service.create_user(name, email, password) if not user: return { 'name': name, 'email': email, 'password': password, 'error': "A user with that email already exists.", 'user_id': cookie_auth.get_user_id_via_auth_cookie(flask.request), } resp = flask.redirect('/account') cookie_auth.set_auth(resp, user.id) return resp
def login_post(): data = request_dict.create() email = data.email.lower().strip() password = data.password.strip() if not email or not password: return { 'email': email, 'password': password, 'error': 'some required fields are missing.', 'user_id': cookie_auth.get_user_id_via_auth_cookie(flask.request), } # TODO: validate a user user = user_service.login_user(email, password) if not user: return { 'email': email, 'password': password, 'error': 'The account does not ecist or password is incorrect', 'user_id': cookie_auth.get_user_id_via_auth_cookie(flask.request), } resp = flask.redirect('/account') cookie_auth.set_auth(resp, user.id) return resp
def register_post(): r = flask.request name = r.form.get('name') email = r.form.get('email', '').lower().strip() password = r.form.get('password').strip() if not name or not email or not password: return { 'name': name, 'email': email, 'password': password, 'error': 'some required fields are missing.', 'user_id': cookie_auth.get_user_id_via_auth_cookie(flask.request), } # TODO: create a user user = user_service.create_user(name, email, password) if not user: return { 'name': name, 'email': email, 'password': password, 'error': 'email already associated with registered user', 'user_id': cookie_auth.get_user_id_via_auth_cookie(flask.request), } resp = flask.redirect('/account') cookie_auth.set_auth(resp, user.id) return resp
def login_post(): vm = LoginViewModel() vm.validate() if vm.error: return vm.to_dict() # todo: log in browser as session resp = flask.redirect("/") cookie.set_auth(resp, str(vm.user.id)) return resp
async def register(request: Request): vm = RegisterViewModel(request) await vm.load() if vm.error: return vm.to_dict() # Create the account account = user_service.create_account(vm.name, vm.email, vm.password) # Login user response = fastapi.responses.RedirectResponse( url='/account', status_code=status.HTTP_302_FOUND) cookie_auth.set_auth(response, account.id) return response
def register_post(): vm = RegisterViewModel() vm.validate() if vm.error: return vm.to_dict() user = user_service.create_user(vm.name, vm.email, vm.password) if not user: vm.error = 'The account could not be created' return vm.to_dict() resp = flask.redirect('/account') cookie_auth.set_auth(resp, user.id) return resp
def login_post(): vm = LoginViewModel() vm.validate() if vm.error: return vm.to_dict() user = user_service.login_user(vm.email, vm.password) if not user: vm.error = "The account does not exist or the password is wrong." return vm.to_dict() resp = flask.redirect('/account') cookie_auth.set_auth(resp, user.id) return resp
async def login_post(request: Request): vm = LoginViewModel(request) await vm.load() if vm.error: return vm.to_dict() # Create the account user = user_service.login_user(vm.email, vm.password) if not user: vm.error = "The account does not exist or the password is wrong." return vm.to_dict() # Login user response = fastapi.responses.RedirectResponse( url='/account', status_code=status.HTTP_302_FOUND) cookie_auth.set_auth(response, user.id) return response