def create(user_id, password): hash = crypt.generate_password_hash(password) try: User(email=user_id, password=hash).save() except Exception as e: flask.flash(e.message, 'danger') else: return True
def login(user_id, password): doc = User.objects(email=user_id).first() is_valid = None if doc: is_valid = crypt.check_password_hash(doc["password"], password) if is_valid: user = UserObj(doc) user.authenticated = True return user
def login(user_id, password): doc = User.objects(email=user_id).first() is_valid = None if doc: is_valid = crypt.check_password_hash(doc['password'], password) if is_valid: user = UserObj(doc) user.authenticated = True return user
def signup(): form = SignupForm(request.form) if form.validate_on_submit(): app.logger.debug('validate') email = request.form.get('email') passwd = request.form.get('passwd') passwd_verify = request.form.get('passwd_verify') if passwd == passwd_verify: result = User.create(email, passwd) app.logger.debug(result) if result: flash('User account successfully created.') return redirect(url_for('index')) else: flash('Passwords do not match!', 'danger') return render_template('signup.html', form=form)
def get(user_id): doc = User.objects(email=user_id).first() if doc: return UserObj(doc)