def addOne(): if not request.json or not 'email' or not 'password' or not 'username' or not 'confirm_password' in request.json: abort(jsonify(devMessage="One or more filed are missing", status="400")) if request.json['password'] != request.json['confirm_password']: abort(jsonify(devMessage="Password are not the same", status="400")) hashed_pwd = bcrypt.generate_password_hash( request.json['password']).decode('utf-8') userObject = { 'username': request.json['username'], 'email': request.json['email'], 'password': hashed_pwd } user = User(username=request.json['username'], email=request.json['email'], password=hashed_pwd) db.session.add(user) try: db.session.commit() except exc.SQLAlchemyError: abort( jsonify(devMessage="Can't add this user. This user alread exist", status="409")) return jsonify({'users': userObject, 'status': '200'})
def create_users(): user1 = User(username='******', password=bcrypt.generate_password_hash('123'), email='*****@*****.**', access='admin') user2 = User(username='******', password=bcrypt.generate_password_hash('123'), email='*****@*****.**') user3 = User(username='******', password=bcrypt.generate_password_hash('123'), email='*****@*****.**') db.session.add(user1) db.session.add(user2) db.session.add(user3) db.session.commit()
def register(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash(form.password.data) user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash(f'Your account has been created successfully!', 'success') return redirect(url_for('users.login')) return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): hashed_passsword = bcrypt.generate_password_hash(form.password.data).decode('utf-8') user=User(username = form.username.data, email = form.email.data, password = hashed_passsword) db.session.add(user) db.session.commit() flash(f'Account Created Successfully for {form.username.data}! Log in ','success') return redirect(url_for('login')) return render_template('register.html',title='Register', form = form )
def register(): form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() return redirect(url_for('login')) return render_template('register.html', title='register', form=form)
def reset_token(token): if current_user.is_authenticated: return redirect(url_for('main.home')) user = User.verify_reset_token(token) if not user: flash('That is an invalid or expired token', 'warning') return redirect(url_for('users.reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash(form.password.data) user.password = hashed_password db.session.commit() flash(f'Your password has been updated. You are now able to log in', 'success') return redirect(url_for('users.login')) return render_template('reset_token.html', title='Reset Password', form=form)
def reset_token(token): user = User.verify_reset_token(token) if not user: flash('That is invalid or expired token', 'warning') return redirect(url_for('reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed_password db.session.commit() flash('Password Successfully Reset') return redirect(url_for('login')) return render_template('reset_token.html', title='reset password', form=form)
def reset_token(token): if current_user.is_authenticated: return redirect(url_for(home)) user = User.verify_reset_token(token) if not user: flash('invalid or expired token', 'warning') return redirect(url_for('users.reset_request')) form = PasswordResetForm() if form.validate_on_submit(): hashed = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed db.session.commit() db.session.commit() flash('password updated', 'success') return redirect(url_for(login)) # app.logger.info('passed') return render_template('reset_token.html', title="enter new password", form=form)