Exemple #1
0
    def post(self):

        if self.check_arguments('phone_number','password','os'):
            self.end('ARG')
            return

        if self.check_arguments_empty('phone_number','password','os'):
            self.end('ARG')
            return

        phone_number = self.arguments['phone_number']
        password = self.arguments['password']

        encrypt_password = User.encrypt_password(password)

        uid = User.gen_uid(phone_number)

        INFO('Register -- uid[%s]' % uid)

        register_sql = "insert into adapter.adapter_login_info (user_id,user_phone,user_password) values ('%(user_id)s','%(user_phone)s','%(user_password)s');"
        user_info = {'password':password,'phone':phone_number,'email':'','name':'','sns':''}

        try:
            if self.redis_user.exists(uid):
                self.end('EXT')
                return 

            self.mysql_master.start_event()
            self.mysql_master.query(register_sql,user_id = uid,user_phone = phone_number,user_password = encrypt_password)
        
            self.redis_user.hmset(uid,user_info)

        except MysqlException:
            self.rollback()
            self.end('SVR')
            return 
        
        except RedisException:
            self.end('SVR')
            return 

        self.mysql_master.end_event()

        self.end('SUC')
Exemple #2
0
    def get(self):

        if self.check_arguments('token'):
            self.end('ARG')
            return

        if self.check_arguments_empty('token'):
            self.end('ARG')
            return

        token = self.arguments['token']

        try:
            if self.redis_token.exists(token):
                uid = self.redis_token.hget(token,'uid')
                
                new_token = User.gen_token(uid,self.host,self.remote_ip)
                new_sessionid = User.gen_sessionid(token)
                token_info = {'uid':uid,'sessionid':new_sessionid}
                self.redis_token.hmset(new_token,token_info)
                self.redis_token.expire(new_token,TOKEN_EXPIRE_TIME)
                self.redis_token.delete(token)

                session_info = {'uid':uid,'token':token}
                self.redis_session.hmset(new_sessionid,session_info)
                #self.expire(new_sessionid,SESSION_EXPIRE_TIME)

                INFO('UserLOginByTOken -- token[%s] -- session[%s] -- uid[%s]' % (new_token,new_sessionid,uid))

                ret_dict = {'token':new_token,'sessionid':new_sessionid}

                self.end('SUC',**ret_dict)
                return 

            else:
                self.end('KEY')
                return 
        
        except RedisException:
                self.end('SVR')
                return
Exemple #3
0
    def get(self):

        if self.check_arguments('identify_id','password'):
            self.end('ARG')
            return

        if self.check_arguments_empty('identify_id','password'):
            self.end('ARG')
            return

        identify_id = self.arguments['identify_id'] 
        password = self.arguments['password'] 

        try:
            uid = User.gen_uid(identify_id)

            if password == self.redis_user.hget(uid,'password'):
                token = User.gen_token(identify_id,self.host,self.remote_ip) 
                sessionid = User.gen_sessionid(token)

                token_info = {'uid':uid,'sessionid':sessionid}
                self.redis_token.hmset(token,token_info)
                self.redis_token.expire(token,TOKEN_EXPIRE_TIME)
                
                session_info = {'uid':uid,'token':token}
                self.redis_session.hmset(sessionid,session_info)

                INFO('Login -- token[%s] -- sessionid[%s] -- uid[%s]' % (token,sessionid,uid))

                ret_dict = {'token':token,'sessionid':sessionid}
                self.end('SUC',**ret_dict)

            else:
                self.end('PWD')
                return
    
        except RedisException:
            self.end('SVR')
            return