Beispiel #1
0
def login():
    from form import loginForm
    from toDB import get_user_list, get_user_passwd
    from hashlib import md5
    form = loginForm()
    if form.validate_on_submit():
        phone = form.phone.data
        user_list = get_user_list()
        if phone not in user_list:
            flash('用户不存在')
            print(
                time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '用户' +
                phone + '尝试登陆:错误的用户名')
        else:
            passwd = md5(form.password.data.encode()).hexdigest()
            ck_passwd = get_user_passwd(phone)
            if passwd == ck_passwd:
                auto_login = form.remember_me.data
                user = User()
                user.id = phone
                login_user(user, auto_login)
                print(
                    time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) +
                    '用户' + phone + '登陆成功')
                return redirect(url_for('index'))
            print(
                time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '用户' +
                phone + '尝试登陆:密码错误')
            flash('密码错误')
    return render_template('login.html', Form=form)
Beispiel #2
0
def request_loader(request):
    from hashlib import md5
    from toDB import get_user_list, get_user_passwd
    user_list = get_user_list()
    username = request.form.get('loginname')
    if username not in user_list:
        return None
    user = User()
    user.id = username
    user.is_authenticated = md5(
        request.form['password'].encode()).hexdigest() == get_user_passwd(
            username)
    return user
Beispiel #3
0
def changePassword():
    from form import change_password_fields
    from toDB import get_user_list, get_user_passwd, changePassWord
    from hashlib import md5
    form = change_password_fields()
    form.phone.data = current_user.get_id()
    if form.validate_on_submit():
        # 校验旧密码
        phone = form.phone.data
        user_list = get_user_list()
        if phone not in user_list:
            flash('用户不存在')
        else:
            passwordOld = md5(form.passwordOld.data.encode()).hexdigest()
            ck_passwd = get_user_passwd(phone)
            if passwordOld == ck_passwd:
                passwd = md5(form.passwordNew.data.encode()).hexdigest()
                t = changePassWord(phone, passwd)
                flash(t)
            flash('密码错误')

    return render_template('changePassword.html', Form=form)