Exemple #1
0
    def post(self):
        user_log.info("GenerateCodeHandler POST.")

        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["phone"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            user_log.error("Generate code protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        phone = req_json["phone"]

        #Generate phone verify code
        code = random.randint(100000, 999999)
        deadline = datetime.now() + timedelta(hours=FD_PHONE_CODE_EXPIRE_TIME)
        if True != dao.savePhoneCode(phone, code, deadline):
            user_log.error("Save phone code failed! Phone: %s, code: %s",
                           phone, code)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_GENERATE_PHONE_CODE_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        #Send verify code to phone
        send_phone_captcha(phone)

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #2
0
    def post(self):
        user_log.info("GenerateCodeHandler POST.")
        
        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["phone"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            user_log.error("Generate code protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR 
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        phone = req_json["phone"]

        #Generate phone verify code
        code = random.randint(100000, 999999)
        deadline = datetime.now() + timedelta(hours=FD_PHONE_CODE_EXPIRE_TIME)
        if True != dao.savePhoneCode(phone, code, deadline):
            user_log.error("Save phone code failed! Phone: %s, code: %s", phone, code)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_GENERATE_PHONE_CODE_FAILED 
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return
            
        #Send verify code to phone 
        send_phone_captcha(phone)

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #3
0
    def get(self):
        if self.arg.step == 'is_account_exist':
            if self.arg.acc_or_pho[0].isalpha():
                response = is_account_or_phone_exist(str=self.arg.acc_or_pho, type='account')
            else:
                response = is_account_or_phone_exist(str=self.arg.acc_or_pho, type='phone')
            # set_cookie
            if response['is_exist']:
                self.set_secure_cookie('step', '1')

            self.write(response)
        elif self.arg.step == 'get_phone_captcha':
            # get step cookie
            if self.get_secure_cookie('step') == '1':
                self.set_secure_cookie('step', '2')
                v = send_phone_captcha(self.arg.phone)
                self.write({'is_success': True})
                return
            else:
                self.write({'is_success': False, 'des': 'no step1'})
                return
        else:
            self.write({'is_success': False, 'res': 'error step!'})