Example #1
0
 def POST(self):
     data = web.input()
     email = data.param
     if users.is_email_available(email):
         return "y"
     else:
         return "这个邮箱已经被使用了"
Example #2
0
    def POST(self):
        data = web.input()
        email = data.forgotEmail
        timestamp = time.mktime(time.localtime())
        prev_timestamp = users.get_last_timestamp(email)
        g = timestamp - prev_timestamp

        if users.is_email_available(email):
            return '{"info":"此邮箱尚未注册过","status":"n"}'
        elif g < 3600:
            return '{"info":"太频繁了","status":"n"}'
        else:
            all = list(
                '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSQUVWXYZ'
            )
            token = ''
            for i in range(32):
                index = random.randint(0, len(all) - 1)
                token = token + all[index]  #生成32位随机数 -> token
            #token = ''.join([str(random.randint(0, 9)) for i in range(32)])
            tm = time.strftime('%Y-%m-%d %H:%M:%S',
                               time.localtime(timestamp))  #格式化时间戳
            users.passwordForgot(email, token,
                                 timestamp)  #传递email到model,将取密码的记录存到库中
            user = users.get_user_by_email(email)
            ua = web.ctx.env.get('HTTP_USER_AGENT')
            ip = web.ctx.ip
            email_templates.forgot(user, token, ua, ip, tm)
            return '{"info":"找回密码邮件已发送,请检查邮箱","status":"y"}'
Example #3
0
    def POST(self):
        data = web.input()
        email = data.forgotEmail
        timestamp = time.mktime(time.localtime())
        prev_timestamp = users.get_last_timestamp(email)
        g = timestamp - prev_timestamp

        if users.is_email_available(email):
            return '{"info":"此邮箱尚未注册过","status":"n"}'
        elif g < 3600:
            return '{"info":"太频繁了","status":"n"}'
        else:
            all = list('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSQUVWXYZ')
            token = ''
            for i in range(32):
                index = random.randint(0,len(all)-1)
                token = token + all[index] #生成32位随机数 -> token
            #token = ''.join([str(random.randint(0, 9)) for i in range(32)])
            tm = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)) #格式化时间戳
            users.passwordForgot(email, token, timestamp) #传递email到model,将取密码的记录存到库中
            user = users.get_user_by_email(email)
            ua = web.ctx.env.get('HTTP_USER_AGENT')
            ip = web.ctx.ip
            email_templates.forgot(user, token, ua, ip, tm)
            return '{"info":"找回密码邮件已发送,请检查邮箱","status":"y"}'
Example #4
0
 def POST(self):
     data = web.input()
     email = data.param
     if users.is_email_available(email):
         return "y"
     else:
         return "这个邮箱已经被使用了"
Example #5
0
    def POST(self):
        email = web.input().email

        #检查是否变动
        old_email = users.get_user_by_id(user.id).email
        if email == old_email:
            return '{"status":"n", "code":"n-wbh", "info":"邮箱地址未变化"}'

        #检查新邮箱是否已经存在
        elif not users.is_email_available(email):
            return '{"status":"n", "code":"n-ybsy", "info":"此邮箱已被使用"}'

        else:
            #更新用户表中email字段
            # users.update(user.id, email=email)

            token = md5.md5(time.ctime() + email).hexdigest()
            t = datetime.datetime.now()
            #更新邮箱验证表中email\confirmed\token字段
            users.update_confirm_email_by_douban_id(user.douban_id, email,
                                                    token, t)

            #发送通知邮件

            email_templates.change_email(email, token)
            print '======email send======'

            # session.reset()
            return '{"status":"y", "code":"y-y", "info":"验证邮件已发送,请通过邮件中的链接来验证此邮箱。在未验证之前,提醒通知还是发到旧邮箱中。"}'
Example #6
0
    def POST(self):
        email = web.input().email

        #检查是否变动
        old_email = users.get_user_by_id(user.id).email
        if email == old_email:
            return '{"status":"n", "code":"n-wbh", "info":"邮箱地址未变化"}'

        #检查新邮箱是否已经存在
        elif not users.is_email_available(email):
            return '{"status":"n", "code":"n-ybsy", "info":"此邮箱已被使用"}'

        else:
            #更新用户表中email字段
            # users.update(user.id, email=email)

            token = md5.md5(time.ctime() + email).hexdigest()
            t = datetime.datetime.now()
            #更新邮箱验证表中email\confirmed\token字段
            users.update_confirm_email_by_douban_id(user.douban_id, email, token, t)

            #发送通知邮件
            
            email_templates.change_email(email, token)
            print '======email send======'

            # session.reset()
            return '{"status":"y", "code":"y-y", "info":"验证邮件已发送,请通过邮件中的链接来验证此邮箱。在未验证之前,提醒通知还是发到旧邮箱中。"}'
Example #7
0
 def register_form(self):
     return form.Form(
         form.Textbox('email',
                      form.notnull,
                      vemail,
                      form.Validator('This email address is already taken.',
                                     lambda x: users.is_email_available(x)),
                      description=u'* 邮箱',
                      class_="form-control"),
         form.Password('password',
                       form.notnull,
                       form.Validator(
                           'Password must at least 5 characters long.',
                           lambda x: users.is_valid_password(x)),
                       description=u'* 密码',
                       class_="form-control"),
         form.Password('re_password',
                       form.notnull,
                       description=u"* 确认密码",
                       class_="form-control"),
         form.Button('SingUp',
                     type='submit',
                     value='SignUp',
                     html=u"注册",
                     class_="btn btn-primary"),
         validators=[
             form.Validator('Password Not Match!.',
                            lambda i: i.password == i.re_password)
         ])
Example #8
0
            lambda i: users.is_correct_password(i.email, i.password))
    ])

register_form = form.Form(
    form.Textbox(
        'username',
        form.notnull,
        form.Validator('用户名已存在.', lambda x: users.is_username_available(x)),
        #form.Validator('请以字母开头,不超过15个字母、数字,保存后不可修改', #todo
        #lambda x: users.is_username_available(x)),
        description='用户名(以字母开头的2-16个字母、数字组合):'),
    form.Textbox('email',
                 form.notnull,
                 vemail,
                 form.Validator('邮箱已经存在.',
                                lambda x: users.is_email_available(x)),
                 description='邮箱:'),
    form.Password('password',
                  form.notnull,
                  form.Validator('密码不能少于6个字符.',
                                 lambda x: users.is_valid_password(x)),
                  description='密码:'),
    form.Textbox('nickname', form.notnull, description='昵称:'),
)

forgot_password_form = form.Form(
    form.Textbox(
        'email',
        form.notnull,
        # form.Validator('请检查您的邮箱地址',
        # lambda x: not users.is_email_available(x)),
Example #9
0
    form.Button('submit', type='submit', value='Change password')
)

nickname_form = form.Form(
    form.Textbox('nickname', 
        form.notnull,
        description='Your new nickname:'),
    form.Button('submit', type='submit', value='Change your nickname')
)

vemail = form.regexp(r'.+@.+', 'Please enter a valid email address')
email_form = form.Form(
    form.Textbox('email', 
        form.notnull, vemail,
        form.Validator('This email address is already taken.', 
        lambda x: users.is_email_available(x)),
        description='Your new email:'),
    form.Button('submit', type='submit', value='Change your email')
)

def render_settings(nickname_form=nickname_form(), email_form=email_form(), password_form=password_form(), on_success_message=''):
    counts = applicants.get_counts()
    user = session.get_session()
    
    return view.layout(
        view.settings(user, nickname_form, email_form, password_form, on_success_message), 
        user, 'settings', counts)

class index:
    @session.login_required
    def GET(self):