Beispiel #1
0
    def get(self):

        mobile = self.get_argument('mobile', None)
        pwd = self.get_argument('pwd', None)

        user = None
        if mobile is None or mobile == '' or pwd is None or pwd == '':
            # 没有传入手机密码,刷新 Token
            uid = self.is_logined()
            user = yield User.objects.get(uid)

        else:
            # 传入手机密码,执行登录
            users = yield User.objects.filter(mobile=mobile).find_all()
            if len(users) == 0:
                # 未找到该用户
                raise HTTPError(**errors.status_22)

            if users[0].password != pwd:
                # 密码有误
                raise HTTPError(**errors.status_23)

            user = users[0]

        # 登陆成功
        user = user.to_dict()
        user['token'] = create_token(str(user['id']))
        self.write_json(user)
Beispiel #2
0
    def post(self):
        # 注册用户 TODO: 手机号验证
        try:
            obj = self.loadjson(self.request.body)
        except:
            self.write_error()

        mobile = self.get_argument('mobile')
        pwd = self.get_argument('pwd')
        users = yield User.objects.filter(mobile=mobile).find_all()
        if len(users) != 0:
            # 手机号码已经被注册
            raise HTTPError(**errors.status_21)

        school_id = self.get_argument('school_id')
        self.vaildate_id(school_id)

        school = yield School.objects.get(self.get_argument('school_id'))
        self.vaildate_resource(school)

        # 注册成功
        user = User(mobile=mobile,
                    password=pwd,
                    nickname='test',
                    school_id=ObjectId(school_id))
        yield user.save()

        user = user.to_dict()
        user['token'] = create_token(str(user['id']))
        self.write_json(user)
Beispiel #3
0
    def get(self):
        mobile = self.get_argument('mobile', None)
        pwd = self.get_argument('pwd', None)

        user = None
        if mobile is None or mobile == '' or pwd is None or pwd == '':
            # 没有传入手机密码,刷新 Token
            uid = self.is_logined()
            user = yield User.objects.get(uid)

        else:
            # 传入手机密码,执行登录
            users = yield User.objects.filter(mobile=mobile).find_all()
            if len(users) == 0:
                # 未找到该用户
                raise HTTPError(**errors.status_22)

            if users[0].password != pwd:
                # 密码有误
                raise HTTPError(**errors.status_23)

            user = users[0]

        # 登陆成功
        user = user.to_dict()
        user['token'] = create_token(str(user['id']))
        self.write_json(user)
Beispiel #4
0
    def post(self):
        # 注册用户 TODO: 手机号验证
        try:
            obj=self.loadjson(self.request.body)
        except:
            self.write_error()

        mobile = self.get_argument('mobile')
        pwd = self.get_argument('pwd')
        users = yield User.objects.filter(mobile=mobile).find_all()
        if len(users) != 0:
            # 手机号码已经被注册
            raise HTTPError(**errors.status_21)

        school_id = self.get_argument('school_id')
        self.vaildate_id(school_id)

        school = yield School.objects.get(self.get_argument('school_id'))
        self.vaildate_resource(school)

        # 注册成功
        user = User(mobile=mobile, password=pwd, nickname='test', school_id=ObjectId(school_id))
        yield user.save()

        user = user.to_dict()
        user['token'] = create_token(str(user['id']))
        self.write_json(user)