def create_user(email, password, name): try: user = User(created=dt.datetime.now()) user.auth = UserAuth(name=name, password=password, email=email) session.add(user) session.commit() except IntegrityError as err: session.rollback() raise err.orig
def index_post(): """ Check validation for SignIn or SignUp :rtype: login page with form """ action = request.GET.get('action', 'signin') username = request.forms.get('username') password = request.forms.get('password') if action == 'signup': password_confirm = request.forms.get('password_confirm') invitation = request.forms.get('invitation') res, msg = User.add(username, password, password_confirm, invitation) else: res, msg = User.auth(username, password) if res: response.set_cookie('username', username, secret=COOKIES_SECRET) redirect('/%s/timeline/' % username) else: return template(action, username=username, msg=msg)
def index_post(): """ Check validation for SignIn or SignUp :rtype: login page with form """ action = request.GET.get('action', 'signin') username = request.forms.get('username') password = request.forms.get('password') if action == 'signup': password_confirm = request.forms.get('password_confirm') invitation = request.forms.get('invitation') res, msg = User.add(username, password, password_confirm, invitation) else: res, msg = User.auth(username, password) if res: response.set_cookie('username', username, secret=COOKIES_SECRET) redirect('/%s/timeline/' % username) else: return template(action, username=username, msg=msg)
def index_post(): """ Check validation for SignIn or SignUp :rtype: login page with form """ action = request.GET.get("action", "signin") username = request.forms.get("username") password = request.forms.get("password") if action == "signup": password_confirm = request.forms.get("password_confirm") invitation = request.forms.get("invitation") res, msg = User.add(username, password, password_confirm, invitation) else: res, msg = User.auth(username, password) if res: response.set_cookie("username", username, secret=COOKIES_SECRET) redirect("/%s/timeline/" % username) else: return template(action, username=username, msg=msg)
def post(self): args = parser.parse_args() try: user = User.auth(args) if user is None: return dict(success=False, message="Incorrect username or password") payload = { 'exp': datetime.datetime.utcnow() + \ datetime.timedelta(days=1), 'iat': datetime.datetime.utcnow(), 'sub': user['user_id'] } return dict(success=True, user=user, token=jwt.encode( payload, SECRET_KEY, algorithm='HS256' ).decode('utf-8')) except Exception as e: return dict(success=False, message=str(e))