Example #1
0
    def post(self):
        username = self.input('username')
        password = self.input('password')

        ret = {'err': True}

        uid = User.get_uid_by_username(username)
        if uid is None:
            ret['msg'] = u'登录名不存在!'
            return self.write(ret)

        is_pwd_ok = User.is_password_valid(uid, password)
        ret['err'] = not is_pwd_ok
        if not is_pwd_ok:
            ret['msg'] = u'登录名或密码错误!'
        else:
            self.session.set('user', username)
            nickname = User.get_nickname_by_uid(uid)
            self.session.set('nickname', nickname)

        self.write(ret)
Example #2
0
    def post(self):
        username = self.input('username')
        password = self.input('password')
        nickname = self.input('nickname')

        ret = {'err': True}

        uid = User.get_uid_by_username(username)
        if uid is not None:
            ret['msg'] = u'登录名已存在!'
            return self.write(ret)

        validator = User.is_valid(**locals())
        if validator is not None:
            ret['filed'] = validator[0]
            ret['msg'] = validator[1]
            return self.write(ret)

        User.save(username, password, nickname)

        ret['err'] = False
        self.write(ret)