Esempio n. 1
0
    def post(self):
        email = request.get_json()['email']
        password = request.get_json()['password']

        user = User.query \
            .with_entities(User.id, User.password, User.username) \
            .filter_by(email=email).first()

        if user is None:
            return {"error": "User not found"}, 401

        if bcrypt.check_password_hash(user.password, password):
            access_token = create_access_token(identity={
                'username': user.username,
                'id': user.id
            },
                                               expires_delta=False)
            result = {
                "refresh_token": None,
                "token": access_token,
                "type": "bearer"
            }
        else:
            result = {"error": "Invalid username and password"}, 401

        return result
Esempio n. 2
0
    def post(self):
        try:
            email = request.get_json()['email']
            password = request.get_json()['password']

            user = User.query \
                .with_entities(User.id, User.flash_id, User.password) \
                .filter_by(email=email).first()

            if user is None:
                return {"error": "User not found"}, 401

            if bcrypt.check_password_hash(user.password, password):
                access_token = create_access_token(identity={
                    'id': user.id,
                    'flash_id': user.flash_id
                })
                result = {"token": f"Bearer {access_token}"}
            else:
                result = {"error": "Invalid username and password"}, 401

            return result

        except:
            traceback.print_exc()
            result = {"error": "Something Wrong"}, 500
Esempio n. 3
0
def login():
    ''' log in users to there account '''
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=True)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('task.create_todo'))
    return render_template('login.html', title='login', form=form)
Esempio n. 4
0
 def signin():
     sign_in = SignIn()
     if sign_in.validate_on_submit():
         user_info = User.query.filter_by(email=sign_in.email.data).first()
         if user_info and bcrypt.check_password_hash(user_info.password, sign_in.password.data):
             print sign_in.password.data
             print sign_in.email.data
             session['name'] = user_info.name
             session['username'] = user_info.username
             session['email'] = user_info.email
             session['logged'] = True
             return redirect('user')
         else:
             # TODO error in logging in
             return True
     return render_template('sign_in.html', sign_in=sign_in, title='Sign In')
Esempio n. 5
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = Users.query.filter_by(username=form.username.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next_page')
            flash('Login successfully', 'success')
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash('Login unsuccesfully, check password and username', 'danger')
    return render_template("login.html", form=form)
Esempio n. 6
0
def login():

    data = request.get_json()

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

    if user:
        flag = bcrypt.check_password_hash(user.password, data['password'])
        if flag:
            token = get_token(user.id, user.email_id, user.password)
            return jsonify({
                'token': token,
                'message': 'Successfully logged in'
            })

    return jsonify(
        {'message': 'Invalid User...Please register using /register'})
Esempio n. 7
0
def login():
	if current_user.is_authenticated:
		return redirect(url_for('mainhome'))
	form = LoginForm()
	if form.validate_on_submit():
		user = User.query.filter_by(email=form.email.data).first()
		try:
			print('doing hash-checking thing')
			if user and bcrypt.check_password_hash(user.password, form.password.data):
				login_user(user, remember=form.remember.data)
				next_page = request.args.get('next')
				return redirect(next_page) if next_page else redirect(url_for('main.home'))
			else:
				flash('Oof, unsuccessful. Maybe go on discord instead.', 'danger')
		except:
			if user and form.password.data == user.password:
				login_user(user, remember=form.remember.data)
				next_page = request.args.get('next')
				return redirect(next_page) if next_page else redirect(url_for('main.home'))
			else:
				flash('Oof, unsuccessful. Maybe go on discord instead.', 'danger')
	return render_template('login.html', title='Login', form=form)
Esempio n. 8
0
 def check_password(self, attempted_password):
     return bcrypt.check_password_hash(self.password_hash, attempted_password)
Esempio n. 9
0
 def check_password(self, password):
     return bcrypt.check_password_hash(self.data['hashed_password'],
                                       password)