def post(self): if not request.json: return abort( 403, description= 'Brakujące argumenty, prosze wypełnić wszystkie pola.') registerData = { 'username': request.json['username'], 'password': request.json['password'], 'email': request.json['email'], 'sex': request.json['sex'] } if not registerData['username'] or not registerData['password'] or ( not registerData['email']) or not registerData['sex']: return abort( 403, description= 'Brakujące argumenty, prosze wypełnić wszystkie pola.') user = User.objects(username=registerData['username']).first() userEmail = User.objects(email=registerData['email']).first() if user: return abort( 403, description='Użytkownik o podanej nazwie już istnieje!') elif userEmail: return abort( 403, description= 'Konto o podanym adresie email już istnieje! prosimy o podanie innego.' ) newUser = User(username=registerData['username'], password=bcrypt.generate_password_hash( registerData['password']), email=registerData['email'], sex=registerData['sex']).save() token = generate_confirmation_token(newUser.email) send_email( newUser.email, 'Aktywacja Konta', render_template('auth/activate.html', confirm_url=url_for('auth.confirm_account', token=token, _external=True))) return jsonify( message= 'Twoje konto zostało pomyślnie utworzone! Na adres e-mail została wysłana wiadomość z linkiem aktywacyjnym - prosimy aktywować konto.' )
def reset_password(token): if current_user.is_authenticated: return redirect(url_for('home')) user = User.verify_reset_token(token) if user is None: flash('That Token Has Expired', 'warning') return redirect(url_for('reset_request')) form = ResetPassword() 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('Account Password Changed You Can Now Login', 'success') return redirect(url_for('login')) return render_template('reset_password.html', title='Reset Password', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = Registration() 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() flash( f'Account Created For {form.username.data} You Can Now Login', 'success' ) #This may produce error if version is less than 3.6 and IDE's that dont support it return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def register(): form = Registration() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') doctor = Doctor(username=form.username.data, email=form.email.data, speciality=form.speciality.data, slmcno=form.slmcno.data, hospital=form.hospital.data, password=hashed_password) db.session.add(doctor) db.session.commit() flash( 'Doctor Your account has been created! You are now able to log in', 'success') return redirect(url_for('doctorlogin')) return render_template('dregdetail.html', title='Register', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('main.home')) else: form = RegistrationForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first( ) # if this returns a user, then the email already exists in database if user: flash('Email address already exists', 'danger') return render_template('register.html', form=form) hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('auth.login')) return render_template('register.html', form=form)
def password(self, password): self.password_hash = bcrypt.generate_password_hash(password).decode( "utf-8")
def hash_pwd(cls, password): if password: hasPas = bcrypt.generate_password_hash( password, app.config.get('BCRYPT_LOG_ROUNDS')).decode('utf-8') return hasPas return False