コード例 #1
0
def set_role():
    user = User.get(request.form['id'])
    role = Role.get(request.form['role'])
    enableDisable = strtobool(request.form['enable'])
    if user is None:
        abort(400, "An invalid user was given!")
    if role is None:
        abort(400, "An invalid role was given!")

    if enableDisable:
        user.add_role(role)
    else:
        user.remove_role(role)
    db.session.commit()
    return ("", http.HTTPStatus.NO_CONTENT)
コード例 #2
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.get(form.username.data)
        if user is not None and user.verify_password(form.password.data):
            login_user(FlaskUser(user), remember=form.remember_me.data)
            next_page = request.args.get('next')
            if not next_page or urlparse(next_page).netloc != '':
                next_page = url_for('main.home')
            return redirect(next_page)
        else:
            return render_template('login.html',
                                   title='Sign In',
                                   form=form,
                                   failed=True)
    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           failed=False)
コード例 #3
0
def load_user(username):
    user = User.get(username)
    if user is None:
        return None
    return FlaskUser(user)
コード例 #4
0
ファイル: user_svc.py プロジェクト: Joeper214/MoonHauz
 def get_current_user(key_only=False):
     user = users.get_current_user()
     return User.get(user.email(), key_only=key_only)
コード例 #5
0
def delete():
    user = User.get(request.form['id'])
    if user is not None:
        user.delete()
        db.session.commit()
    return ("", http.HTTPStatus.NO_CONTENT)
コード例 #6
0
 def get_waiter(self):
     return User.get(self.waiter)
コード例 #7
0
 def get_current_user(key_only=False):
     user = users.get_current_user()
     return User.get(user.email(), key_only=key_only)