Exemplo n.º 1
0
 def process_step(self, form):
     if "user-phone_number" in form.data:
         phone_number = form.data["user-country_code"] + form.data["user-phone_number"]
         token = generate_token()
         self.request.session["generated_token"] = token
         msg = "Verification token: {}".format(token)
         send_sms.delay(msg, phone_number)
     return self.get_form_step_data(form)
Exemplo n.º 2
0
 def process_step(self, form):
     if 'user-phone_number' in form.data:
         phone_number = form.data['user-country_code'] + form.data[
             'user-phone_number']
         token = generate_token()
         self.request.session['generated_token'] = token
         msg = "Verification token: {}".format(token)
         send_sms.delay(msg, phone_number)
     return self.get_form_step_data(form)
Exemplo n.º 3
0
 def process_step(self, form):
     if "user-username" in form.data:
         user = authenticate(username=form.data["user-username"], password=form.data["user-password"])
         user_profile = UserProfile.objects.get(user=user)
         phone_number = user_profile.phone_number
         token = generate_token()
         self.request.session["login_token"] = token
         msg = "Verification token: {}".format(token)
         send_sms.delay(msg, phone_number)
     return self.get_form_step_data(form)
Exemplo n.º 4
0
 def process_step(self, form):
     if 'user-username' in form.data:
         user = authenticate(username=form.data['user-username'],
                             password=form.data['user-password'])
         user_profile = UserProfile.objects.get(user=user)
         phone_number = user_profile.phone_number
         token = generate_token()
         self.request.session['login_token'] = token
         msg = "Verification token: {}".format(token)
         send_sms.delay(msg, phone_number)
     return self.get_form_step_data(form)
Exemplo n.º 5
0
def sms_captcha():
    form = MSMCaptchaForm(request.form)

    if not form.validate():
        return restful.params_error()
    telephone = form.telephone.data

    if mcache.get(telephone + '_'):
        return restful.params_error('请求过于频繁')

    captcha = Captcha.gene_text(4)
    mcache.set(telephone, captcha.lower(), 300)
    mcache.set(telephone + '_', 1, 60)

    send_sms.delay(telephone, captcha)
    # ret = alidayu.send_sms(telephone, key=captcha)
    # ret = json.loads(ret)

    return restful.success()
Exemplo n.º 6
0
def schedule_sms(receiver, content, tz=DEFAULT_TZ):
    from tasks import send_sms

    now = datetime.now(tz)
    current_time = now.time()

    if any(imap(lambda x: x[0] <= current_time and current_time <= x[1],
                INTERVALS)):
        send_sms.delay(receiver, content)
        return
    availables = filter(lambda x: current_time <= x,
                        imap(lambda x: x[0], INTERVALS))
    if availables:
        # send it at the beginning of next interval
        eta = datetime.combine(now.date(), min(availables))
    else:
        # send it tomorrow
        eta = datetime.combine((now + timedelta(days=1)).date(),
                               min(imap(lambda x: x[0], INTERVALS)))

    eta = tz.localize(eta)
    send_sms.apply_async(args=[receiver, content], eta=eta)
Exemplo n.º 7
0
def schedule_sms(receiver, content, tz=DEFAULT_TZ):
    from tasks import send_sms

    now = datetime.now(tz)
    current_time = now.time()

    if any(
            imap(lambda x: x[0] <= current_time and current_time <= x[1],
                 INTERVALS)):
        send_sms.delay(receiver, content)
        return
    availables = filter(lambda x: current_time <= x,
                        imap(lambda x: x[0], INTERVALS))
    if availables:
        # send it at the beginning of next interval
        eta = datetime.combine(now.date(), min(availables))
    else:
        # send it tomorrow
        eta = datetime.combine((now + timedelta(days=1)).date(),
                               min(imap(lambda x: x[0], INTERVALS)))

    eta = tz.localize(eta)
    send_sms.apply_async(args=[receiver, content], eta=eta)
Exemplo n.º 8
0
def send_sms(receiver, content):
    from tasks import send_sms
    send_sms.delay(receiver, content)
Exemplo n.º 9
0
def send_sms(receiver, content):
    from tasks import send_sms
    send_sms.delay(receiver, content)