Пример #1
0
def register():
    if request.method == 'GET':
        return render_template('register.html')
    else:
        username = request.form.get('username')
        password = request.form.get('password')
        repeat_password = request.form.get('repeat_password')
        email = request.form.get('email')
        ip = request.remote_addr
        if username == '' or username.isspace():
            return 'error1'
        elif email == '' or email.isspace():
            return 'error2'
        elif password == '':
            return 'error3'
        elif repeat_password == '':
            return 'error4'
        elif password != repeat_password:
            return 'error5'
        elif not check_username(username):
            return 'error6'
        elif not check_mail(email):
            return 'error7'
        elif db_users.Users().register(username=username, password=password, email=email, last_ip=ip):
            session['username'] = username
            return 'success'
        else:
            return 'error8'
Пример #2
0
def login():
    if request.method == 'GET':
        return render_template('login.html')
    else:
        username = request.form.get('username')
        password = request.form.get('password')
        if check_mail(username):
            login_type = 'email'
        else:
            login_type = 'username'

        if username == '':
            return 'error1'
        elif password == '':
            return 'error2'
        elif db_users.Users().vaild(username, password, login_type):
            session['username'] = username
            return 'success'
        else:
            return 'false'