示例#1
0
def login():
    pass
    form = LoginForm()
    if(BINGONE__WEB__USER__KEY in session):
        flash('您已登陆')
        return index()
    if request.method == 'POST':
        # if(form.register.data == True):
        #     flash('欢迎注册校友订阅系统')
        #     return render_template('common/form.html',form=RegisterForm(),)
        if form.validate_on_submit():
            username = form.username.data
            password = form.password.data
            user = DAO.getUser(User.username == username)
            if user != None and user.verify_password(password):
                session[BINGONE__WEB__USER__KEY] = user.username
                session[BINGONE__WEB__USERID__KEY] = user.user_id
                userCache.put(user.username,user.user_id)
                session.permanent = False
                if username == ADMIN.username and ADMIN.verify_password(password):
                    session[BINGONE__WEB__ADMIN__KEY] = True
                return execSuccess('login success')
            return bad_request(msg='login failed')
    flash('欢迎登陆校友订阅系统')
    return defaultRender('common/form.html', form=form,register=True)
示例#2
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = LoginForm()
    user = User.query.filter_by(username=form.username.data).first()
    if form.validate_on_submit():
        if user is None or not user.check_password(form.password.data):
            flash("Invalid Username or Passowrd")
            return redirect(url_for('login'))
        login_user(user)
        return redirect(url_for('home'))

    return render_template('login.html', title="Login- Generic", form=form)
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        return redirect(next_page)
    return render_template('login.html', title='Sign In', form=form)
示例#4
0
def login():
    form = LoginForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            data = form.data
            user = Admin.query.filter_by(username=data['username']).first()
            if user.check_pwd(data['password']):
                session['admin'] = data['username']
                if data['remember']:
                    session.permanent = True
                return redirect(url_for('admin.index'))
            else:
                flash('密码错误')
                return redirect(url_for('admin.login'))
    return render_template('admin/login.html', form=form)
示例#5
0
文件: routes.py 项目: csWendy/TodoApp
def login():
    if current_user.is_authenticated:
        return redirect(url_for('user'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None:
            flash('Invalid username.Please register first.')
            return redirect(url_for('login'))
        login_user(user)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('home')
        # flash('Login requested for user {}'.format(form.username.data))
        return redirect(next_page)
    return render_template('login.html', title='Login', form=form)
示例#6
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        print(user.password)
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user)
            return redirect(url_for('home'))
        else:
            flash(
                'Login Unsuccessfull! Please check email and password again.',
                'danger')
    return render_template('login.html', title='Login', form=form)
示例#7
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('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=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash('Login unsuccessful, please check email and or password!',
                  'danger')
        return redirect(url_for('home'))
    return render_template('login.html', title='Login', form=form)
示例#8
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form = LoginForm()
    if not form.validate_on_submit():
        return render_template('login.html',
                               title='Login',
                               form=form,
                               User=User,
                               password_length={'min': TRACKER_PASSWORD_LENGTH_MIN,
                                                'max': TRACKER_PASSWORD_LENGTH_MAX})

    user = user_assign_new_token(form.user)
    user.is_authenticated = True
    login_user(user)
    return redirect(url_for('index'))
示例#9
0
def login():
    #check if the user is already authenticated; no need to user to authenicate twice
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    #form.validate_on_submit does the form procressing work, gathers the data and runs all the validators
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            #Flash is a function that sends a notification to the user across different webpages
            flash('Invalid username or password')
            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        #Redirect function instructs the client web browswer to automatically navigate to a different page
        return redirect('/index')
    return render_template('login.html', title='Sign In', form=form)
示例#10
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('blog.index'))

    form = LoginForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        remember = form.remember.data
        admin = Admin.query.first()
        if admin:
            if admin.username == username and admin.check_password(password):
                login_user(admin, remember)
                flash('Welcome back', 'info')
                return redirect_back()
            flash('无效的用户名或者帐号', 'warning')
        else:
            flash('无效的帐号', 'warning')
    return render_template('auth/login.html', form=form)
示例#11
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('user', username=current_user.username))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user:
            if form.password.data == user.password:
                login_user(user, remember=form.remember.data)
                if user.reportTally >= 15 and user.reportTally <20:
                    return redirect(url_for('warning', username = form.username.data))
                elif user.reportTally >=20:
                    return redirect(url_for('deleteAcc'))
                flash('You were logged in')
                if user.surveyVisted == 1:
                    return redirect(url_for('user', username=current_user.username))
                else:
                    return redirect(url_for('survey'))
        flash('Incorrect username/password. Try again.')
    return render_template('Login.html', form=form, title="Login")
示例#12
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_pwd(form.password.data):
            flash('无效的用户名或密码')
            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        # 让登录的用户关注自己(如果没关注的话)
        if not user.is_following(user):
            db.session.add(user.follow(user))
            db.session.commit()
        flash('用户登录的用户名是:%s,是否记住我:%s' %
              (form.username.data, form.remember_me.data))
        return redirect(request.args.get('next') or url_for('index'))

    return render_template('login.html', title='登录', form=form)
示例#13
0
def login():
    form = LoginForm()
    status = {'status': 404}
    if form.validate_on_submit():
        u = User.query.filter_by(username=form.username.data).first()
        if u.delflag == 1:
            status['error'] = "用户名不存在,请确认用户名后登陆"
            logging.error(status['error'])
        elif u.verify_password(form.password.data):
            status['status'] = 200
            # 生成token
            status['userToken'] = u.encode_auth_token(u.userid).decode()
            logging.info("登陆")
        else:
            status['status'] = 403
            status['error'] = '密码错误, 请确认密码后登陆'
            logging.error(status['error'])
    else:
        status['status'] = 400
        status['error'] = '输入不正确'
        logging.error(status['error'])
    return jsonify(status)
示例#14
0
def signup():
    signup_form = LoginForm()
    context = {'signup_form': signup_form}

    if signup_form.validate_on_submit():
        user_name = signup_form.user_name.data
        password = signup_form.password.data

        user_doc = get_user(user_name)

        if user_doc.to_dict() is None:
            password_hash = generate_password_hash(password)
            user_data = UserData(user_name, password_hash)
            user_put(user_data)

            user = UserModel(user_data)
            login_user(user)
            flash('Bienvenido')
            return redirect(url_for('hello'))

        else:
            flash('El usuario ya existe')

    return render_template('signup.html', **context)
示例#15
0
def login():
	form = LoginForm()
	if form.validate_on_submit():
		flash('Login requested for user, remember_me={}'.format(form.username.data, form.remember_me.data))
		return redirect('/index')
	return render_template('login.html', title='Login', form=form)