def get_token(): incoming = request.get_json() user = User.get_user_with_email_and_password(incoming["email"], incoming["password"]) if user: return jsonify(token=generate_token(user)) return jsonify(error=True), 403
def get_token(): email = request.form.get('email') password = request.form.get('password') user = User.get_user_by_email_and_password(email, password) if user: return jsonify(token=generate_token(user)) return jsonify(error=True), 403
def create_user(): incoming = request.get_json() try: User.create_user(incoming) except IntegrityError: return jsonify(message="User with that email already exists"), 409 new_user = User.query.filter_by(email=incoming["email"]).first() return jsonify(id=new_user.id, token=generate_token(new_user))
def create_user(): incoming = request.get_json() user = User(email=incoming["email"], password=incoming["password"]) db.session.add(user) try: db.session.commit() except IntegrityError: return jsonify(message="User with that email already exists"), 409 new_user = User.query.filter_by(email=incoming["email"]).first() return jsonify(id=user.id, token=generate_token(new_user))
def create_user(): incoming = request.get_json() user = User(name=incoming['name'], email=incoming['email'], password=incoming['password']) db.session.add(user) try: db.session.commit() except IntegrityError: return jsonify(message='User with that email already exists'), 409 new_user = User.query.filter_by(email=incoming['email']).first() return jsonify(user=new_user, token=generate_token(new_user))
def signup_post(): if request.method == 'POST': email = request.form.get('email') password = request.form.get('password') user = User.get_user_by_email_and_password(email, password) if user: flash('Email address already exists') return redirect(url_for('signup')) new_user = User.create_user(email, password) ## NEEDS MODIFICATION # return redirect(url_for('login')) return jsonify(id=new_user.id, token=generate_token(user=new_user, SECRET_KEY=app.secret_key)) else: return render_template('signup.html')
def login(): request_json = request.get_json() data = request_json['data'] email = data['email'] password = data['password'] user = User.query.filter_by(email=email).first() status = False if user: if user.password == password: login_user(user) print 'logged in' status = True return jsonify(token=generate_token(user)) else: print 'cant log in' return jsonify({'result': status})
def register(): captcha = get_param('captcha', Struct.Attr, True) login = get_param('login', Struct.Login, True) passwd = get_param('passwd', Struct.Pwd, True) slug = get_param('slug', Struct.Attr, True) meta = get_param('meta', Struct.Dict, default={}) login = login.lower() slug = process_slug(slug) User = current_app.mongodb.User user = User.find_one_by_login(login) if user is not None: raise UserLoginOccupied if not check_captcha(CAPTCHA_REGISTER, login, captcha): raise UserCaptchaError if User.find_one_by_slug(slug) is not None: raise UserNameOccupied del_captcha(CAPTCHA_REGISTER, login) user = User() user['login'] = login user['slug'] = slug user['meta'] = meta user['password_hash'] = generate_hashed_password(passwd) user['status'] = User.STATUS_ACTIVATED user.save() token = generate_token({ 'user_id': str(user['_id']), 'sha': get_user_hmac_sha(user), }) return { 'login': user['login'], 'slug': user['slug'], 'token': token, 'id': user['_id'], 'updated': user['updated'], 'status': user['status'], }
def update_password(): passwd = get_param('passwd', Struct.Pwd, True) old_passwd = get_param('old_passwd', Struct.Pwd, True) user = g.user pass_checked = check_hashed_password(str(user['password_hash']), old_passwd) if pass_checked is not True: raise UserWrongPassword user['password_hash'] = generate_hashed_password(passwd) user.save() token = generate_token({ 'user_id': str(user['_id']), 'sha': get_user_hmac_sha(user), }) return { 'id': user['_id'], 'token': token, 'updated': user['updated'], }
def login(): login = get_param('login', Struct.Login, True) passwd = get_param('passwd', Struct.Pwd, True) user = helper_get_user_by_login(login) pass_checked = check_hashed_password(str(user['password_hash']), passwd) if pass_checked is not True: raise UserWrongPassword token = generate_token({ 'user_id': str(user['_id']), 'sha': get_user_hmac_sha(user), }) return { 'id': user['_id'], 'login': user['login'], 'slug': user['slug'], 'updated': user['updated'], 'status': user['status'], 'token': token }