Exemplo n.º 1
0
    def register_user(cls, account=None, identify_code=None, passwd=None):
        # username may be phone_num or email
        if identify_code is None:
            identify_code = random.randint(111111, 999999)
            # call API send identify_code to phone num
            if len(account) == 11:  # from app/web/weixin
                msg = u"[做好事]: %d ,请与10分钟内完成手机号验证操作" % identify_code
                send_short_message(account, msg)
            app.logger.debug("Get identify_code:%s for user %s" % (str(identify_code), account))

            # set it to redis {account:identify_code} and set expire time
            redis_db.set(account, identify_code)
            redis_db.expire(account, 600)

            return {'identify_code': str(identify_code)}
        else:
            # get identify_code from redis {account:identify_code}
            saved_identify_code = redis_db.get(account)

            if identify_code == saved_identify_code:
                # delete identify_code from redis {account:identify_code}
                redis_db.delete(account)

                app.logger.debug("Identify success for account %s" % account)
                token, user_obj_id = cls.add_user(account, passwd)
                return {"account": account, "token": token, "user_id": user_obj_id}
            else:
                app.logger.debug("Identify error:%s,code:%s,saved:%s" % (account, identify_code, saved_identify_code))
                return {'error': 'Identify code not match'}
Exemplo n.º 2
0
    def del_user(self, user_id):
        app.logger.debug("del_user start:[%s]" % (user_id))

        # delete head portrait from store

        # delete from db
        # user_obj_id = user_db.user_collection.remove(one_user).inserted_id

        # clear redis token
        redis_db.delete(self.user_id)

        # delete his activities in db

        app.logger.debug("del_user [%s:%s]" % (self.user_id, user_id))
        return {'del': user_id}
Exemplo n.º 3
0
    def logout(self):
            app.logger.debug("Login failed:[%s]" % self.user_id)
            # clear redis token
            redis_db.delete(self.user_id)

            return {'logout': self.user_id}