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