Ejemplo n.º 1
0
def register():
    form = RegistrationForm()
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = Users(username=form.username.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Account created, now you are able to login', 'success')
        return redirect(url_for('login'))
    return render_template("register.html", form=form)
Ejemplo n.º 2
0
def register():
    ''' this function register user and if user was login user can not come to this page '''
    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).decode('utf-8')
        new_user = User(user_name=form.user_name.data,
                        email=form.email.data,
                        password=hashed_password)
        db.session.add(new_user)
        db.session.commit()
        return redirect(url_for('users.login'))
    return render_template('register.html', title='register', form=form)
Ejemplo n.º 3
0
def register():
	if current_user.is_authenticated:
		return redirect(url_for('mainhome'))
	form = RegistrationForm()
	if form.validate_on_submit():
		try:
			print('hashed the password')
			hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
		except:
			print('no hash')
			hashed_password = form.password.data
		user = User(username=form.username.data, email=form.email.data, password=hashed_password)
		db.session.add(user)
		db.session.commit()
		flash("Your account has been created! Don't worry, use a tracker blocker if you are worried you're being tracked!", 'success')
		return redirect(url_for('main.home'))
	return render_template('register.html', title='Register', form=form)
Ejemplo n.º 4
0
 def signup():
     sign_up = SignUp()
     if sign_up.validate_on_submit():
         validate_email(sign_up.email.data)
         sign_up.validate_email(sign_up.email.data)
         sign_up.validate_username(sign_up.username.data)
         password_crypt = bcrypt.generate_password_hash(sign_up.password.data).encode('utf-8')
         new_user = User(username=sign_up.username.data, name=sign_up.name.data, email=sign_up.email.data,
                         password=password_crypt, role_id=2)
         db.session.add(new_user)
         session['name'] = new_user.name
         session['username'] = new_user.username
         session['email'] = new_user.email
         db.session.commit()
         send_mail(sign_up.email.data, 'You have successfully registered!', 'mail', user='******')
         return redirect('user')
     return render_template('signup.html', signUp=sign_up, title='Sign Up')
Ejemplo n.º 5
0
def register():

    data = request.get_json()

    user = Users.query.filter_by(email_id=data['email_id'])

    if user.count() == 0:
        pw_hash = bcrypt.generate_password_hash(data['password'])
        new_user = Users(email_id=data['email_id'], password=pw_hash)
        db.session.add(new_user)
        db.session.commit()
        return jsonify({'message': 'Successfully registered'})
    else:
        return jsonify({
            'message':
            'You are already registered or Please login using /login'
        })
Ejemplo n.º 6
0
    def post(self):
        data = request.get_json()
        now = datetime.datetime.now()

        user = User(email=data['email'],
                    password=bcrypt.generate_password_hash(
                        data['password']).decode('utf-8'),
                    person_id=None,
                    created_at=now,
                    updated_at=now)

        db.session.add(user)
        db.session.commit()

        return {
            "data": {
                "email": user.email,
                "created_at": now.strftime("%Y-%m-%d %H:%M:%S"),
                "updated_at": now.strftime("%Y-%m-%d %H:%M:%S")
            }
        }
Ejemplo n.º 7
0
 def password(self, plain_text_password):
     self.password_hash = bcrypt.generate_password_hash(plain_text_password).decode(
         "utf-8"
     )
Ejemplo n.º 8
0
 def set_password(self, new_password):
     self.data['hashed_password'] = bcrypt.generate_password_hash(
         new_password)