Beispiel #1
0
    def login_user(data):
        try:
            if current_user.is_authenticated:
                response_object = {
                    'status': 'Invalid',
                    'message': 'Already Logged In',
                }
                return response_object, 300
            user = User.query.filter_by(username=data.get('username')).first()
            if user is None:
                response_object = {
                    'status': 'fail',
                    'message': 'User does not exist. '
                }
                return response_object, 403
            if user and user.check_password(data.get('password')):
                if user.is_verified:
                    # convert string to bool
                    if data.get('remember').lower() == 'true' or data.get(
                            'remember').lower() == 'yes':
                        remem = True
                    else:
                        remem = False
                    flask_login_user(user, remember=remem)
                    response_object = {
                        'status': 'success',
                        'message': 'Successfully logged in.',
                    }

                    login_info = {
                        'id': current_user.id,
                        'username': current_user.username,
                    }
                    return login_info, 200
                else:
                    response_object = {
                        'status': 'fail',
                        'message':
                        'Please verify your email before first login',
                    }
                    return response_object, 402
            else:
                response_object = {
                    'status': 'fail',
                    'message': 'email or password does not match.',
                }
                return response_object, 401

        except BaseException:
            LOG.error('Login Failed', exc_info=True)
            response_object = {
                'status': 'fail',
                'message': 'Try again',
            }
            return response_object, 500
Beispiel #2
0
    def login_user(data):
        try:
            if current_user.is_authenticated:
                response_object = {
                    'status': 'Invalid',
                    'message': 'Already Logged In',
                }
                return response_object, 300
            user = User.query.filter_by(email=data.get('email')).first()
            if user and user.check_password(data.get('password')):
                if user.is_verified:
                    # convert string to bool
                    if data.get('remember').lower() == 'true' or data.get(
                            'remember').lower() == 'yes':
                        remem = True
                    else:
                        remem = False
                    flask_login_user(user, remember=remem)
                    response_object = {
                        'status': 'Success',
                        'message': 'Successfully logged in.',
                    }
                    return response_object, 200
                else:
                    response_object = {
                        'status': 'fail',
                        'message':
                        'Please verify your email before first login',
                    }
                    return response_object, 401
            else:
                response_object = {
                    'status': 'fail',
                    'message': 'email or password does not match.',
                }
                return response_object, 401

        except Exception as e:
            LOG.error('Login Failed')
            LOG.debug(traceback.print_exc())
            response_object = {
                'status': 'fail',
                'message': 'Try again',
            }
            return response_object, 500
Beispiel #3
0
    def login():

        if current_user.is_authenticated:
            return redirect(url_for("home"))

        form = LoginForm()
        if form.validate_on_submit():
            login_message = login_user(datalake_connection, form.email.data,
                                       form.password.data)
            flash(login_message.message, login_message.category)
            if login_message.category == "success":
                flask_login_user(user=login_message.user,
                                 remember=form.remember.data)
                next_page = request.args.get("next")
                if next_page:
                    return redirect(next_page)
                return redirect(url_for("tests"))
        return render_template("login.html", title="Login", form=form)
Beispiel #4
0
def login_user(user, *args, **kwargs):
    logged_in = flask_login_user(user, *args, **kwargs)
    session['token'] = generate_token(user)
    user.last_login = db.func.now()
    
    try:
        db.session.commit()
    except Exception as e:
        app.logger.exception(e)

    return logged_in
Beispiel #5
0
def login_user():
    # 如果已經登入了 還打這網址 就直接導回首頁
    if current_user.is_active:
        return redirect(url_for('main.index'))
    # 如果沒有登入
    form = LoginForm()
    # 如果validate成功
    if form.validate_on_submit():
        # 在資料庫裡查詢那個user
        user = User.query.filter_by(email=form.email.data).first()
        # 如果有查到email而且password hash對的話
        if user is not None and user.verify_password(form.password.data):
            # 如果有勾記住我, 就直接記住你
            flask_login_user(user, remember=form.remember_me.data)
            # flash一個message, 丟進隊伍, base.html加入相對應get_flash_message
            flash(u'成功登入')
            # 如果成功登入就導到首頁
            return redirect(url_for('main.index'))
        # user沒查到或者密碼部正確
        flash(u'不存在的帳號名稱或密碼不正確')
    # 沒成功回去login.html
    return render_template('auth/login.html', form=form)
Beispiel #6
0
def login_user(app, request_data):
    if 'username' not in request_data or 'password' not in request_data:
        raise BadRequest('Username or password not specified')
    username = request_data.get('username', None)
    password = request_data.get('password', None)
    pss_user, pss_user_dict = app.table_proxy.pss_users.get_pss_user(
        username=username)
    if not pss_user or not pss_user.verify_password(password):
        raise Unauthorized('Bad password')
    flask_logout_user()
    if flask_login_user(pss_user) is False:
        raise Unauthorized('User is not active')
    identity_changed.send(app._get_current_object(),
                          identity=Identity(pss_user.pss_user_id))
    return pss_user_dict
Beispiel #7
0
def login_user(user, *args, **kwargs):
    """Allow login user by its id."""
    if type(user) in [int, long]:
        user = UserInfo(user)
    return flask_login_user(user, *args, **kwargs)
Beispiel #8
0
def login_user(user, *args, **kwargs):
    """Allow login user by its id."""
    if type(user) in [int, long]:
        user = UserInfo(user)
    return flask_login_user(user, *args, **kwargs)
Beispiel #9
0
def login_user(nick, password, keep_login):
    user = User.query.filter_by(nick=nick).first()
    if user is None or not user.check_password(password):
        raise RuntimeError('昵称或密码错误')
    flask_login_user(user, keep_login)
Beispiel #10
0
 def login_new_user(self, user):
     flask_login_user(user)
Beispiel #11
0
 def login_user(self, user, remember_me):
     flask_login_user(user, remember_me)