Example #1
0
    def post(self, *args, **kwargs):
        username = self.get_argument('us', None)
        pwd = self.get_argument('pwd', None)
        pwd2 = self.get_argument('pwd2', None)
        code = self.get_argument('code', None)
        msg = ''
        if username and pwd and pwd2:
            sql = "select id from user where username like '%s'" % ('%'+username+'%')
            status = mysql(sql,1,('id')).run
            if status:
                msg = u'该用户名已被注册<br>'
            if pwd != pwd2:
                msg = u'密码不一致<br>'

        else:
            msg = u'请补全信息'
        if msg:
            self.render('register.html', msg=msg)
        else:
            import datetime
            print 'aaaaaaa', username
            hash_pwd = hashlib.new("md5", pwd).hexdigest()
            sql = """insert into user(username, password, add_time) values ('%s', '%s', '%s')""" %(
                username, hash_pwd, datetime.datetime.now().strftime('%Y-%m-%d')
            )
            mysql(sql, 2).run
            self.redirect('/login')
Example #2
0
 def post(self, *args, **kwargs):
     name = self.get_argument('name')
     pwd = self.get_argument('pwd')
     if name and pwd:
         pwd = hashlib.new('md5', pwd).hexdigest()
         column = ('id', 'login_count')
         sql = "select id,login_count from user where username='******' and password='******'" %(name, pwd)
         result = mysql(sql, 1, column).run
         if result:
             self.set_secure_cookie('user', name)
             sql = "update user set last_login='******', login_count=%s where id=%s" %(
                 datetime.datetime.now(),
                 result['login_count']+1,
                 result['id']
             )
             mysql(sql, 2)
             #写入redis
             next = self.get_cookie('next', '/')
             self.redirect(str(next))
         err_msg = u'账号密码错误'
         self.render('login.html', err_msg=err_msg)