Ejemplo n.º 1
0
def findps():
    response_object = {'status': 'success'}
    if request.method == 'POST':
        #获取前端传来的数据
        data = request.get_json()
        username = data['username']
        newpassword = data['password']
        code = data['code']
        #验证新密码是否合乎规范
        vPs = validate.ValidatePassword(newpassword)
        #验证邮箱是否已经注册
        #未注册
        if statement.Isregister(username) != True:
            response_object['message'] = "该邮箱账号尚未注册,请检查并重试!"
        #已注册
        else:
            current_code = statement.find_item('CODE', 'register', username)[0]
            if code == current_code:
                if vPs == True:
                    sql = "UPDATE register SET  PASSWORD = \'%s\' WHERE USERNAME = \'%s\' " % (
                        newpassword, username)
                    msg, res = statement.update_mysql(sql)
                    if res == True:
                        response_object['message'] = "密码重置成功!"
                        response_object['resCode'] = 101
                    else:
                        response_object['message'] = "密码重置失败,请重试!"
                else:
                    response_object['message'] = "无效密码,请重新输入!"
            else:
                response_object['message'] = "验证码不正确!"
    else:
        response_object['message'] = "Unallowed request method."
    return jsonify(response_object)
Ejemplo n.º 2
0
def save_recordC():
    if request.method == 'POST':
        n = request.form['number']
        username = request.form['nm']
        mm = request.form['mm']

        sql = "UPDATE admin SET Name = \'%s\', Password = \'%s\' WHERE ID = \'%s\' " % (
            username, mm, n)
        msg, res = statement.update_mysql(sql)
        print(msg)
        return redirect(url_for('find_all'))
    else:
        return redirect(url_for('update_record'))
Ejemplo n.º 3
0
def save_record():
    if request.method == 'POST':
        n = request.form['number']
        username = request.form['nm']
        xm = request.form['xm']
        password = request.form['ps']
        code = request.form['cd']
        sql = "UPDATE register SET USERNAME = \'%s\', XM = \'%s\', PASSWORD = \'%s\', CODE = \'%s\' WHERE ID = \'%s\' " % (
            username, xm, password, code, n)
        msg, res = statement.update_mysql(sql)
        print(msg)
        return redirect(url_for('find_all'))
    else:
        return redirect(url_for('update_record'))
Ejemplo n.º 4
0
def save_recordA():
    if request.method == 'POST':
        n = request.form['number']
        username = request.form['nm']
        xg = request.form['xg']
        mb = request.form['mb']
        sz = int(request.form['sz'])
        rq = int(request.form['rq'])
        sql = "UPDATE habit SET USERNAME = \'%s\', TITLE = \'%s\', HABIT_OBJECT = \'%s\', OBJECT_NUMBER = \'%s\', DATETIME = \'%s\' WHERE ID = \'%s\' " % (
            username, xg, mb, sz, rq, n)
        msg, res = statement.update_mysql(sql)
        print(msg)
        return redirect(url_for('find_all'))
    else:
        return redirect(url_for('update_record'))
Ejemplo n.º 5
0
def save_recordB():
    if request.method == 'POST':
        n = request.form['number']
        username = request.form['nm']
        xg = request.form['xg']
        mb = request.form['mb']
        sz = int(request.form['sz'])
        rq = request.form['rq']
        wc = request.form['wc']
        sql = "UPDATE inputDetail SET USERNAME = \'%s\', TITLE = \'%s\', ATTR = \'%s\', STANDARD = \'%s\', DATE = \'%s\', Finished = \'%s\' WHERE ID = \'%s\' " % (
            username, xg, mb, sz, rq, wc, n)
        msg, res = statement.update_mysql(sql)
        print(msg)
        return redirect(url_for('find_all'))
    else:
        return redirect(url_for('update_record'))
Ejemplo n.º 6
0
def GetSms():
    T = '验证码已成功发送!'
    F = '获取验证码失败!'
    response_object = {'status': 'success'}
    if request.method == 'POST':
        data = request.get_json()
        username = data['username']
        #验证邮箱是否合法
        vEmail = validate.ValidateEmail(username)
        #如果该邮箱合法
        if vEmail == True:
            #验证该邮箱是否已注册
            #未注册账号获取验证码:注册___________________ 获取getsms table的验证码
            if statement.Isregister(username) != True:
                insert_v = False
                update_v = False
                #随机获取验证码
                new_code = ''
                new_code = email.get_code()
                #如果生成新密码、更新数据库、发送邮件成功
                if validate.ValidateCode(new_code) == True:
                    #如果该邮箱从未获取过验证码:插入insert数据库
                    if statement.Isgetsms(username) != True:
                        #getsms插入记录
                        sql = "insert into getsms values (null,\'%s\',\'%s\')" % (
                            username, new_code)
                        msg, insert_v = statement.insert_mysql(sql)
                    #如果该邮箱曾获取过验证码:更新update数据库
                    else:
                        #getsms更新记录
                        sql = "UPDATE getsms SET CODE = \'%s\' WHERE USERNAME = \'%s\' " % (
                            new_code, username)
                        msg, update_v = statement.update_mysql(sql)
                    #如果插入or更新成功
                    if update_v == True or insert_v == True:
                        #发送验证码
                        sed = email.send_mail(username, new_code)
                        if sed == True:
                            response_object['message'] = T
                            response_object['resCode'] = 101
                        else:
                            response_object['message'] = '无效邮箱,请重新尝试!'
                    else:
                        response_object['message'] = F
                #如果生成新密码、更新数据库、发送邮件失败
                else:
                    response_object['message'] = F
            #已注册账号获取验证码:登录______________获取register table的验证码
            else:
                origional_code = statement.find_item(
                    'CODE', 'register', username)[0]  #获取register表格里该用户名的验证码
                print("以前:{}".format(origional_code))
                #获取新密码
                code = ''
                code = email.get_code()
                print("现在:{}".format(code))
                #如果生成新密码、更新数据库、发送邮件成功
                if validate.ValidateCode(code) == True:
                    #更新数据库
                    sql = "UPDATE register SET CODE = \'%s\' WHERE USERNAME = \'%s\' " % (
                        code, username)
                    msg, res = statement.update_mysql(sql)
                    #发送邮件
                    sed = email.send_mail(username, code)
                    if res == True and sed == True:
                        response_object['message'] = T
                        response_object['resCode'] = 101
                    else:
                        response_object['message'] = F
                #如果生成新密码、更新数据库、发送邮件失败
                else:
                    response_object['message'] = F
        #如果该邮箱不合法
        else:
            response_object['message'] = vEmail
    else:
        response_object['message'] = "Unallowed request method."
    return jsonify(response_object)