Example #1
0
    def post(self):
        username = self.get_argument('username', None)
        password = self.get_argument('password', None)
        # repasswd = self.get_argument('repassword', None)
        email = self.get_argument('email', None)
        sex = self.get_argument('sex', None)
        avatar = self.request.files['avatar'][0]

        encrypted = encrypt_password(password)
        b64avatar = base64.b64encode(avatar['body'])

        sql = """insert into `users`(username, password, email, sex, avatar)
        values (%s, %s, %s, %s, %s)"""
        yield self.async_task(self.db.insert, sql, username, encrypted, email,
                              sex, b64avatar)
        # Send confirm email and redirect to email link
        token = gen_token()
        url = '{0}://{1}/verify/{2}'.format(self.request.protocol,
                                            self.request.host, token)
        subject = mail.SIGNUP_SUBJECT
        message = mail.SIGNUP_MESSAGE.format(name=username, url=url)
        from_addr = options.from_addr
        from_pwd = options.from_pwd
        smtp_server = options.smtp_server
        # Use task queue send email
        taskq.tqueue.Queue().enqueue(mail.send_email,
                                     (from_addr, from_pwd, username, email,
                                      message, subject, smtp_server))
        # Insert into table and wait to verify
        sql = 'insert into `verify` (token, username) values (%s, %s)'
        yield self.async_task(self.db.insert, sql, token, username)
        self.render("mail.html", username=username, message="注册成功")
Example #2
0
    def post(self):
        username = self.get_argument('username', None)
        password = self.get_argument('password', None)
        # repasswd = self.get_argument('repassword', None)
        email = self.get_argument('email', None)
        sex = self.get_argument('sex', None)
        avatar = self.request.files['avatar'][0]

        encrypted = encrypt_password(password)
        b64avatar = base64.b64encode(avatar['body'])

        sql = """insert into `users`(username, password, email, sex, avatar)
        values (%s, %s, %s, %s, %s)"""
        yield self.async_task(self.db.insert,
                              sql, username, encrypted, email, sex, b64avatar)
        # Send confirm email and redirect to email link
        token = gen_token()
        url = '{0}://{1}/verify/{2}'.format(
            self.request.protocol, self.request.host, token)
        subject = mail.SIGNUP_SUBJECT
        message = mail.SIGNUP_MESSAGE.format(name=username, url=url)
        from_addr = options.from_addr
        from_pwd = options.from_pwd
        smtp_server = options.smtp_server
        # Use task queue send email
        taskq.tqueue.Queue().enqueue(
            mail.send_email,
            (from_addr, from_pwd, username, email,
             message, subject, smtp_server))
        # Insert into table and wait to verify
        sql = 'insert into `verify` (token, username) values (%s, %s)'
        yield self.async_task(self.db.insert, sql, token, username)
        self.render("mail.html", username=username, message="注册成功")
Example #3
0
 def post(self, token):
     username = self.get_argument('username', None)
     password = self.get_argument("password", None)
     encrypted = encrypt_password(password)
     sqlu = 'update users set password=%s where username=%s'
     yield self.async_task(self.db.update, sqlu, encrypted, username)
     sqld = 'delete from losspw where token=%s and username=%s'
     yield self.async_task(self.db.update, sqld, token, username)
     self.render('pwchanged.html', username=username)
Example #4
0
 def post(self, token):
     username = self.get_argument('username', None)
     password = self.get_argument("password", None)
     encrypted = encrypt_password(password)
     sqlu = 'update users set password=%s where username=%s'
     yield self.async_task(self.db.update, sqlu, encrypted, username)
     sqld = 'delete from losspw where token=%s and username=%s'
     yield self.async_task(self.db.update, sqld, token, username)
     self.render('pwchanged.html', username=username)
Example #5
0
 def post(self):
     email = self.get_argument('email', None)
     password = self.get_argument('password', None)
     remember = self.get_argument('remember', None)
     sql = 'select * from users where email=%s'
     user = yield self.async_task(self.db.get, sql, email)
     if encrypt_password(password) == user.password:
         self.write('ok')
         if remember and remember == 'remember':
             self.set_secure_cookie('username', user.username, 7)
         self.set_secure_cookie('username', user.username, 1)
         return
     self.write('fail')
Example #6
0
 def post(self):
     email = self.get_argument('email', None)
     password = self.get_argument('password', None)
     remember = self.get_argument('remember', None)
     sql = 'select * from users where email=%s'
     user = yield self.async_task(self.db.get, sql, email)
     if encrypt_password(password) == user.password:
         self.write('ok')
         if remember and remember=='remember':
             self.set_secure_cookie('username', user.username, 7)
         self.set_secure_cookie('username', user.username, 1)
         return
     self.write('fail')