Ejemplo n.º 1
0
    def post(self, *args, **kwargs):
        next = self.get_argument('next', '')
        account = self.get_argument('account', None)
        password = self.get_argument('password', '')
        rsa_encrypt = self.get_argument('rsa_encrypt', 0)

        if settings.login_pwd_rsa_encrypt and int(
                rsa_encrypt) == 1 and len(password) > 10:
            private_key = sys_config('sys_login_rsa_priv_key')
            password = RSAEncrypter.decrypt(password, private_key)

        if not account:
            return self.error('账号不能够为空')

        if Func.is_mobile(account):
            member = Member.Q.filter(Member.mobile == account).first()
        elif Func.is_email(account):
            member = Member.Q.filter(Member.email == account).first()
        else:
            member = Member.Q.filter(Member.username == account).first()

        if member is None:
            return self.error('用户名或者密码错误')

        if int(member.status) == 0:
            return self.error('用户被“禁用”,请联系客服')
        if check_password(password, member.password) is not True:
            return self.error('用户名或者密码错误')

        Member.login_success(member, self)

        self.clear_cookie(valid_code_key)

        return self.success(next=next)
Ejemplo n.º 2
0
    def post(self, *args, **kwargs):
        id = self.get_argument('id', None)

        params = self.params()

        params['status'] = params.get('status', 0)

        if not id:
            return self.error('用户ID不能为空')

        username = params.get('username', None)
        if username:
            count = Member.Q.filter(Member.id != id).filter(
                Member.username == username).count()
            if count > 0:
                return self.error('用户名已被占用')

        mobile = params.get('mobile', None)
        params.pop('mobile', None)
        if mobile:
            params['mobile'] = mobile
            if Func.is_mobile(mobile):
                count = Member.Q.filter(Member.id != id).filter(
                    Member.mobile == mobile).count()
                if count > 0:
                    return self.error('电话号码已被占用')

        email = params.get('email', None)
        params.pop('email', None)
        if email:
            params['email'] = email
            if Func.is_email(email):
                count = Member.Q.filter(Member.id != id).filter(
                    Member.email == email).count()
                if count > 0:
                    return self.error('Email已被占用')

        password = params.get('password', None)
        params.pop('password', None)
        if password:
            rsa_encrypt = params.get('rsa_encrypt', 0)
            if settings.login_pwd_rsa_encrypt and int(
                    rsa_encrypt) == 1 and len(password) > 10:
                private_key = sys_config('sys_login_rsa_priv_key')
                # print('password: '******'password'] = make_password(password)

        params.pop('_xsrf', None)
        params.pop('rsa_encrypt', None)
        Member.Q.filter(Member.id == id).update(params)
        Member.session.commit()

        # update member cache info
        member = Member.Q.filter(Member.id == id).first()
        cache_key = member.cache_info(self)

        return self.success(data=params)
Ejemplo n.º 3
0
    def post(self, *args, **kwargs):
        params = self.params()

        params['status'] = params.get('status', 0)

        if not params.get('username', None):
            return self.error('用户名不能为空')
        if not params.get('password', None):
            return self.error('密码不能为空')

        count = Member.Q.filter(Member.username == params['username']).count()
        if count > 0:
            return self.error('用户名已被占用')

        if Func.is_mobile(params.get('mobile', '')):
            count = Member.Q.filter(Member.mobile == params['mobile']).count()
            if count > 0:
                return self.error('电话号码已被占用', data=params)

        if Func.is_email(params.get('email', '')):
            count = Member.Q.filter(Member.email == params['email']).count()
            if count > 0:
                return self.error('Email已被占用')

        password = params.get('password')
        rsa_encrypt = params.get('rsa_encrypt', 0)
        if settings.login_pwd_rsa_encrypt and int(
                rsa_encrypt) == 1 and len(password) > 10:
            private_key = sys_config('sys_login_rsa_priv_key')
            password = RSAEncrypter.decrypt(password, private_key)
            params['password'] = make_password(password)

        params.pop('_xsrf', None)
        params.pop('rsa_encrypt', None)
        params['uuid'] = Func.uuid32()
        member = Member(**params)
        Member.session.add(member)
        Member.session.commit()

        return self.success(data=member.as_dict())