コード例 #1
0
ファイル: view.py プロジェクト: QiaoHaiZhong/rebang
 def post(self):
     if USER_MODEL==2:
         self.redirect('/sigin')
         return
     
     name = str(self.get_argument('name','').lower().encode('utf-8'))
     open_id = str(self.get_cookie('open_id',''))
     access_token = str(self.get_cookie('access_token',''))
     
     errors = []
     if name and open_id and access_token:
         access_token_in_kvdb = kv.get('qq_' +str(open_id))
         if access_token_in_kvdb == access_token:
             pass
         else:
             self.redirect('/sigin')
             return
         
         if len(name)<20:
             if re.search('^[a-zA-Z0-9]+$', name):
                 check_obj = Member.check_user_name(str(name))
                 if check_obj:
                     errors.append('该用户名已被注册,请换一个吧')
                 else:
                     u_flag = Member.add_user(str(name), access_token)
                     if u_flag and kv.set('qq_' +str(open_id), str(name)):
                         #注册成功
                         #set sr_code
                         code_list = [access_token]
                         u_topic_time = kv.get('u_topic_time:'+name)
                         if u_topic_time:
                             code_list.append(u_topic_time)
                         u_comment_time = kv.get('u_comment_time:'+name)
                         if u_comment_time:
                             code_list.append(u_comment_time)
                         #code_md5 = md5(''.join(code_list)).hexdigest()
                         
                         self.set_cookie('username', name, path="/", expires_days = 365 )
                         self.set_cookie('usercode', str(md5(''.join(code_list)).hexdigest()), path="/", expires_days = 365 )
                         self.set_cookie('userflag', str(u_flag), path="/", expires_days = 365 )
                         self.redirect('/setavatar?qq=1')
                         return
                     else:
                         errors.append('服务器出现意外错误,请稍后再试')
             else:
                 errors.append('用户名只能包含字母和数字')
         else:
             errors.append('用户名太长了')
     else:
         errors.append('用户名必填')
         
     self.echo('setname.html', {
         'title': "设置名字",
         'errors':errors,
         'name':name,
     }, layout='_layout.html')        
コード例 #2
0
    def post(self):
        name = str(self.get_argument('name', '').lower().encode('utf-8'))
        pw = self.get_argument('pw', '')

        errors = []
        if name and pw:
            if len(name) < 20 or len(pw) < 20:
                if re.search('^[a-zA-Z0-9]+$', name):
                    check_obj = Member.check_user_name(str(name))
                    if check_obj:
                        errors.append('该用户名已被注册,请换一个吧')
                    else:
                        pwmd5 = md5(pw.encode('utf-8')).hexdigest()
                        u_flag = Member.add_user(str(name), pwmd5)
                        if u_flag:
                            #注册成功
                            self.set_cookie('username',
                                            name,
                                            path="/",
                                            expires_days=365)
                            self.set_cookie('usercode',
                                            md5(pwmd5).hexdigest(),
                                            path="/",
                                            expires_days=365)
                            self.set_cookie('userflag',
                                            str(u_flag),
                                            path="/",
                                            expires_days=365)
                            self.redirect('/setavatar')
                            return
                        else:
                            errors.append('服务器出现意外错误,请稍后再试')
                else:
                    errors.append('用户名只能包含字母和数字')
            else:
                errors.append('用户名或密码太长了')
        else:
            errors.append('用户名和密码必填')

        self.echo('sigin.html', {
            'title': "注册",
            'errors': errors,
            'name': name,
            'newest_node': Node.get_newest(),
        },
                  layout='_layout.html')
コード例 #3
0
ファイル: view.py プロジェクト: QiaoHaiZhong/rebang
 def post(self):
     name = str(self.get_argument('name','').lower().encode('utf-8'))
     pw = self.get_argument('pw','')
     
     errors = []
     if name and pw:
         if len(name)<20 or len(pw)<20:
             if re.search('^[a-zA-Z0-9]+$', name):
                 check_obj = Member.check_user_name(str(name))
                 if check_obj:
                     errors.append('该用户名已被注册,请换一个吧')
                 else:
                     pwmd5 = md5(pw.encode('utf-8')).hexdigest()
                     u_flag = Member.add_user(str(name), pwmd5)
                     if u_flag:
                         #注册成功
                         self.set_cookie('username', name, path="/", expires_days = 365 )
                         self.set_cookie('usercode', md5(pwmd5).hexdigest(), path="/", expires_days = 365 )
                         self.set_cookie('userflag', str(u_flag), path="/", expires_days = 365 )
                         self.redirect('/setavatar')
                         return
                     else:
                         errors.append('服务器出现意外错误,请稍后再试')
             else:
                 errors.append('用户名只能包含字母和数字')
         else:
             errors.append('用户名或密码太长了')
     else:
         errors.append('用户名和密码必填')
         
     self.echo('sigin.html', {
         'title': "注册",
         'errors':errors,
         'name':name,
         'newest_node': Node.get_newest(),
     }, layout='_layout.html')        
コード例 #4
0
    def post(self):
        if USER_MODEL == 2:
            self.redirect('/sigin')
            return

        name = str(self.get_argument('name', '').lower().encode('utf-8'))
        open_id = str(self.get_cookie('open_id', ''))
        access_token = str(self.get_cookie('access_token', ''))

        errors = []
        if name and open_id and access_token:
            access_token_in_kvdb = kv.get('qq_' + str(open_id))
            if access_token_in_kvdb == access_token:
                pass
            else:
                self.redirect('/sigin')
                return

            if len(name) < 20:
                if re.search('^[a-zA-Z0-9]+$', name):
                    check_obj = Member.check_user_name(str(name))
                    if check_obj:
                        errors.append('该用户名已被注册,请换一个吧')
                    else:
                        u_flag = Member.add_user(str(name), access_token)
                        if u_flag and kv.set('qq_' + str(open_id), str(name)):
                            #注册成功
                            #set sr_code
                            code_list = [access_token]
                            u_topic_time = kv.get('u_topic_time:' + name)
                            if u_topic_time:
                                code_list.append(u_topic_time)
                            u_comment_time = kv.get('u_comment_time:' + name)
                            if u_comment_time:
                                code_list.append(u_comment_time)
                            #code_md5 = md5(''.join(code_list)).hexdigest()

                            self.set_cookie('username',
                                            name,
                                            path="/",
                                            expires_days=365)
                            self.set_cookie(
                                'usercode',
                                str(md5(''.join(code_list)).hexdigest()),
                                path="/",
                                expires_days=365)
                            self.set_cookie('userflag',
                                            str(u_flag),
                                            path="/",
                                            expires_days=365)
                            self.redirect('/setavatar?qq=1')
                            return
                        else:
                            errors.append('服务器出现意外错误,请稍后再试')
                else:
                    errors.append('用户名只能包含字母和数字')
            else:
                errors.append('用户名太长了')
        else:
            errors.append('用户名必填')

        self.echo('setname.html', {
            'title': "设置名字",
            'errors': errors,
            'name': name,
        },
                  layout='_layout.html')