Ejemplo n.º 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')
Ejemplo n.º 2
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