示例#1
0
文件: apis.py 项目: dodoru/chiki
    def post(self):
        args = self.get_args()
        if current_user.is_authenticated():
            um.models.UserLog.logout(current_user.id, args['device'])

        logout_user()
        return success()
示例#2
0
文件: apis.py 项目: dodoru/chiki
    def post(self):
        action = request.args.get('action')
        args = self.get_args()
        self.validate(action, args)

        EmailCode = um.models.EmailCode
        code = EmailCode.objects(email=args['email'], action=action).first()
        if code:
            if code.timelimit:
                abort(EMAIL_CODE_TIME_LIMIT)
        else:
            code = EmailCode(email=args['email'], action=action)

        if code.action in EmailCode.REGISTERED_ACTIONS and code.registered:
            abort(EMAIL_REGISTERED)
        elif code.action in EmailCode.UNREGISTERED_ACTIONS and not code.registered:
            abort(EMAIL_UNREGISTERED)

        condom.heart('send_email_code')

        code.make()
        code.save()
        code.send()

        return success(email_url=get_email_url(code.email))
示例#3
0
    def success(self, action, scope, access, next):
        callback = self.success_callback
        if not callback:
            return '授权成功,请设置回调'

        res = callback(action, scope, access, next)
        return res if res else (success() if is_json() else redirect(next))
示例#4
0
文件: wxauth.py 项目: daimon99/chiki
    def success(self, action, scope, access, next):
        callback = self.success_callback
        if not callback:
            return '授权成功,请设置回调'

        res = callback(action, scope, access, next)
        return res if res else (success() if is_json() else redirect(next))
示例#5
0
文件: apis.py 项目: dodoru/chiki
    def post(self):
        if not current_user.is_user():
            abort(NEED_BIND)

        args = get_args()
        self.handle(args)
        current_user.save()

        return success(**userinfo(current_user))
示例#6
0
文件: wxauth.py 项目: endsh/chiki
    def success(self, action, scope, access, next):
        callback = self.success_callback
        if not callback:
            return '授权成功,请设置回调'

        res = callback(action, scope, access, next)
        if res:
            return res

        if is_json():
            if current_user.is_authenticated():
                return success()
            return error(msg='登录出错')
        return redirect(next)
示例#7
0
文件: apis.py 项目: OdayWu/chiki
 def get(self):
     item = AndroidVersion.objects(enable__in=Enable.get()).order_by('-id').first()
     if item:
         spm = parse_spm(request.args.get('spm'))
         url = item.url or current_app.config.get('HOST') + '/android/latest.html?channel=%d' % (spm[2] or 1001)
         return success(
             version=item.version,
             code=item.id,
             log=item.log,
             url=url,
             force=item.force,
             date=str(item.created).split(' ')[0],
         )
     abort(SERVER_ERROR)
示例#8
0
 def get(self):
     item = AndroidVersion.objects(enable__in=Enable.get()).order_by('-id').first()
     if item:
         spm = parse_spm(request.args.get('spm'))
         url = item.url or current_app.config.get('HOST') + '/android/latest.html?channel=%d' % (spm[2] or 1001)
         return success(
             version=item.version,
             code=item.id,
             log=item.log,
             url=url,
             force=item.force,
             date=str(item.created).split(' ')[0],
         )
     abort(SERVER_ERROR)
示例#9
0
    def success(self, action, scope, access, next):
        callback = self.success_callback
        if not callback:
            return '授权成功,请设置回调'

        res = callback(action, scope, access, next)
        if res:
            return res

        if is_json():
            if current_user.is_authenticated():
                return success()
            return error(msg='登录出错')
        return redirect(next)
示例#10
0
    def success(self, action, scope, access, next, config=None):
        if next and 'redirect=true' in next:
            return redirect(add_args(next, mp_openid=access['openid']))
        callback = self.success_callback
        if not callback:
            return '授权成功,请设置回调'

        if type(callback) == functools.partial or \
                'config' in inspect.getargspec(callback)[0]:
            res = callback(action, scope, access, next, config=config)
        else:
            res = callback(action, scope, access, next)

        if res:
            return res

        if is_json():
            if current_user.is_authenticated():
                return success()
            return error(msg='登录出错')
        return redirect(next)
示例#11
0
    def post(self):
        if not um.allow_phone:
            abort(ACCESS_DENIED)

        action = request.args.get('action')
        args = self.get_args()
        self.validate(action, args)

        PhoneCode = um.models.PhoneCode
        if current_app.is_web and not current_user.is_authenticated() \
                and action not in PhoneCode.PASS_ACTIONS:
            verify_code = request.form.get('verify_code')
            code_len = current_app.config.get('VERIFY_CODE_LEN', 4)
            key = 'users_' + action + '_phone'
            code, times = get_verify_code(key, code_len=code_len)
            if code.lower() != verify_code.lower():
                validate_code(key)
                abort(VERIFY_CODE_ERROR, refresh=True)

        code = PhoneCode.objects(phone=args['phone'], action=action).first()
        if code:
            if code.timelimit:
                abort(PHONE_CODE_TIME_LIMIT)
        else:
            ip = get_ip()
            ua = request.headers.get('User-Agent', '')
            code = PhoneCode(phone=args['phone'], action=action, ip=ip, ua=ua)

        if code.action in PhoneCode.REGISTERED_ACTIONS and code.registered:
            abort(PHONE_REGISTERED)
        elif code.action in PhoneCode.UNREGISTERED_ACTIONS and not code.registered:
            abort(PHONE_UNREGISTERED)

        condom.heart('send_phone_code')

        code.make()
        code.save()
        code.send()

        return success()
示例#12
0
文件: apis.py 项目: dodoru/chiki
 def success(self, user, args):
     if um.config.get('reset_password_auto_login'):
         return um.funcs.login(user, device=args['device'], key=self.key)
     return success()
示例#13
0
文件: apis.py 项目: dodoru/chiki
 def post(self):
     action = request.args.get('action')
     args = self.get_args()
     self.validate(action, args)
     return success()
示例#14
0
 def success(self, user, args):
     if um.config.register_auto_login:
         return um.funcs.login(user, device=args['device'], key=self.key)
     return success()
示例#15
0
文件: apis.py 项目: dodoru/chiki
 def get(self):
     return success(**um.funcs.userinfo(current_user))
示例#16
0
文件: apis.py 项目: dodoru/chiki
def login(user, device='', key='', remember=True):
    login_user(user, remember=remember)
    user.login()
    um.models.UserLog.login(user.id, device, key)
    return success(**um.funcs.userinfo(user))
示例#17
0
文件: apis.py 项目: PyFansLi/chiki
 def success(self, user, args):
     if um.config.register_auto_login:
         return um.funcs.login(user, device=args['device'], key=self.key)
     return success()
示例#18
-2
文件: apis.py 项目: dodoru/chiki
    def post(self):
        action = request.args.get('action')
        args = self.get_args()
        self.validate(action, args)

        if current_app.is_web:
            verify_code = request.form.get('verify_code')
            code_len = current_app.config.get('VERIFY_CODE_LEN', 4)
            key = 'users_' + action + '_phone'
            code, times = get_verify_code(key, code_len=code_len)
            if code.lower() != verify_code.lower():
                validate_code(key)
                abort(VERIFY_CODE_ERROR, refresh=True)

        PhoneCode = um.models.PhoneCode
        code = PhoneCode.objects(phone=args['phone'], action=action).first()
        if code:
            if code.timelimit:
                abort(PHONE_CODE_TIME_LIMIT)
        else:
            code = PhoneCode(phone=args['phone'], action=action)

        if code.action in PhoneCode.REGISTERED_ACTIONS and code.registered:
            abort(PHONE_REGISTERED)
        elif code.action in PhoneCode.UNREGISTERED_ACTIONS and not code.registered:
            abort(PHONE_UNREGISTERED)

        condom.heart('send_phone_code')

        code.make()
        code.save()
        code.send()

        return success()