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()
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()