def signup(request):
    from auth.models import User
    from auth import load_backend, login
    from users.models import Profile, EmailVerify
    from market_buy.forms import BuyerForm

    form = BuyerForm(request.POST or None)
    if form.is_valid():
        """ Generate Auth User """
        user = User.objects.create_user(form.cleaned_data["username"],
                                        form.cleaned_data["email"],
                                        form.cleaned_data["password1"])

        user.first_name = form.cleaned_data["first_name"]
        user.last_name = form.cleaned_data["last_name"]
        user.is_active = False
        user.save()
        """ Set profile """
        profile = Profile(user=user)
        profile.save()
        """ Send mail to confirm account """
        email_verify = EmailVerify(user=user, user_activation=True)
        code = email_verify.generate_code()
        email_verify.save()

        # TODO: remove this
        send_mail_account_confirmation(user, email_verify.code,
                                       request.marketplace)

        #        return HttpResponseRedirect(reverse('confirmemail', args=[code]))
        #        for backend in settings.AUTHENTICATION_BACKENDS:
        #            if user == load_backend(backend).get_user(user.pk):
        #                user.backend = backend
        #                break
        #        if hasattr(user, 'backend'):
        #            login(request, user)

        if request.session.get('sell_signup', False):
            request.flash['message'] = _(
                "<h5>Please check your email and confirm your account to start selling...</h5>"
            )
            request.flash['severity'] = "success"
            return HttpResponseRedirect(reverse('market_sell_signup'))
        else:
            request.flash['message'] = _(
                "<h5>Please check your email and confirm your account. Once confirmed you can Buy or Sell on GreatCoins.com</h5>"
            )
            request.flash['severity'] = "success"
            return HttpResponseRedirect(reverse('market_home'))
    else:
        #request.method == GET
        if request.GET.has_key('sell_signup'):
            request.session['sell_signup'] = request.GET.get(
                'sell_signup', '') == '1'

    return render_to_response(
        '%s/buy/register.html' % request.marketplace.template_prefix,
        {'form': form}, RequestContext(request))
示例#2
0
def send_retrieve_password_mail(user):
    code = generate_random_code()
    appears = EmailVerify.objects.filter(code=code)
    if len(appears) != 0:
        raise FieldError("unexpected random_code function produced same codes")
    email_record = EmailVerify(email=user.email,
                               code=code,
                               verify_type="forget")
    email_record.save()
    return _send_the_mail(user.email, *generate_retrieve_mail(code))
def signup(request):
    from auth.models import User
    from auth import load_backend, login
    from users.models import Profile, EmailVerify
    from market_buy.forms import BuyerForm
    
    form = BuyerForm(request.POST or None)
    if form.is_valid():
        """ Generate Auth User """
        user = User.objects.create_user(form.cleaned_data["username"],
                                        form.cleaned_data["email"], 
                                        form.cleaned_data["password1"])
        
        user.first_name = form.cleaned_data["first_name"]
        user.last_name = form.cleaned_data["last_name"]
        user.is_active = False
        user.save()
        
        """ Set profile """
        profile = Profile(user=user)
        profile.save()

        """ Send mail to confirm account """
        email_verify = EmailVerify(user=user, user_activation=True)
        code = email_verify.generate_code()
        email_verify.save()
        
        # TODO: remove this
        send_mail_account_confirmation(user, email_verify.code, request.marketplace)        
        
#        return HttpResponseRedirect(reverse('confirmemail', args=[code]))
#        for backend in settings.AUTHENTICATION_BACKENDS:
#            if user == load_backend(backend).get_user(user.pk):
#                user.backend = backend
#                break
#        if hasattr(user, 'backend'):
#            login(request, user)
        
        if request.session.get('sell_signup',False):
            request.flash['message'] = _("<h5>Please check your email and confirm your account to start selling...</h5>")
            request.flash['severity'] = "success"
            return HttpResponseRedirect(reverse('market_sell_signup'))
        else:
            request.flash['message'] = _("<h5>Please check your email and confirm your account. Once confirmed you can Buy or Sell on GreatCoins.com</h5>")
            request.flash['severity'] = "success"
            return HttpResponseRedirect(reverse('market_home'))
    else:
        #request.method == GET
        if request.GET.has_key('sell_signup'):
            request.session['sell_signup'] = request.GET.get('sell_signup','') == '1'

    return render_to_response('%s/buy/register.html'% request.marketplace.template_prefix, 
                              {'form': form},
                              RequestContext(request))
示例#4
0
def send_email_code(email, send_type="register"):
    data = {
        "appid": settings.ONLINE_EMAIL_APPID,
        "to": email,
        "signature": settings.ONLINE_EMAIL_APPKEY,
        "project": "B8yc31"
    }

    # 生成验证码
    code = generate_digits_code()

    # 发送邮件
    if send_type == "register":
        subject = "用户账号注册邮件"
    elif send_type == "forget":
        subject = "用户密码重置邮件"
    elif send_type == "modify":
        subject = "用户邮箱变更邮件"
    else:
        return "无效的send_type:{0}".format(send_type)

    data["subject"] = subject
    data["vars"] = json.dumps({"code": code})
    response = requests.post(settings.ONLINE_EMAIL_URL, data=data)
    res = json.loads(response.text)
    if res.get("status") == "error":
        return res.get("msg")
    else:
        EmailVerify(email=email, code=code, send_type=send_type).save()
示例#5
0
def send_online_email_code(email, send_type="register"):
    data = {
        "appid": settings.ONLINE_EMAIL_APPID,
        "to": email,
        "signature": settings.ONLINE_EMAIL_APPKEY,
    }

    # 保存数据到数据库
    if send_type == "modify":
        code = generate_digits_code(length=6)
    else:
        code = generate_code(length=64)

    # 发送邮件
    if send_type == "register":
        subject = "用户账号激活邮件"
        project = "PwalT1"
    elif send_type == "forget":
        subject = "用户密码重置邮件"
        project = "AIk5G1"
    elif send_type == "modify":
        subject = "更改用户邮箱邮件"
        project = "zasOO4"
    else:
        return "无效的send_type:{0}".format(send_type)

    data["subject"] = subject
    data["project"] = project
    data["vars"] = json.dumps({"code": code})
    response = requests.post(settings.ONLINE_EMAIL_URL, data=data)
    res = json.loads(response.text)
    if res.get("status") == "error":
        return res.get("msg")
    else:
        EmailVerify(email=email, code=code, send_type=send_type).save()
示例#6
0
def send_register_email(email, send_type='register'):
    # 生成16位的验证码
    code = random_str(16)

    # 保存验证码
    email_record = EmailVerify()
    email_record.code = code
    email_record.email = email
    email_record.send_type = send_type
    email_record.save()

    # 设置邮箱的发送信息
    if send_type == 'register':
        email_title = '潭州课堂用户注册激活链接'
        email_body = '请点击此链接激活你的账号:http://127.0.0.1:8000/active/{0}'.format(
            code)
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        if send_status:
            pass

    if send_type == 'forget':
        email_title = '潭州课堂用户密码找回链接'
        email_body = '请点击此链接找回你的密码:http://127.0.0.1:8000/reset/{0}'.format(
            code)
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        if send_status:
            pass
示例#7
0
def send_register_email(email, send_type="register"):
    # 实例化Email model.
    email_record = EmailVerify()

    code = random_str(16)

    email_record.code = code
    email_record.email = email
    email_record.send_type = send_type

    email_record.save()

    # 设置邮箱的发送信息
    email_title = ""
    email_body = ""

    if send_type == "register":

        email_title = u"在线注册激活链接"
        email_body = u"请点击下面的链接激活你的账号:http://192.168.83.128:8000/active/{0}".format(
            code)
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        if send_status:
            pass

    if send_type == "forget":

        email_title = u"密码找回激活链接"
        email_body = u"请点击下面的链接找回你的密码:http://192.168.83.128:8000/reset/{0}".format(
            code)
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        if send_status:
            pass
示例#8
0
def send_register_email(email,send_type='register'):
    email_record=EmailVerify()
    code=random_str(16)
    email_record.chack_code=code
    email_record.email=email
    email_record.send_type=send_type
    email_record.save()

    email_title=''
    email_body=''

    if send_type=='register':
        email_title=u'在线注册激活链接'
        email_body=u'请点击下面的链接激活你的账号:http://127.0.0.1:8000/active/{0}'.format(code)

        #def send_mail(subject, message, from_email, recipient_list
        send_status=send_mail(email_title,email_body,EMAIL_FROM,[email])
        if send_status:
            pass

    if send_type=='forget':
        email_title=u'密码找回激活链接'
        email_body=u'请点击下面的链接找回你的密码:http://127.0.0.1:8000/reset/{0}'.format(code)

        #def send_mail(subject, message, from_email, recipient_list
        send_status=send_mail(email_title,email_body,EMAIL_FROM,[email])
        if send_status:
            pass
示例#9
0
def send_email_verify(email, send_type):
    code = get_random_code()
    if send_type == 'changeemail':
        code = get_random_code(4)
    email_ver = EmailVerify()
    email_ver.email = email
    email_ver.send_type = send_type
    email_ver.code = code
    email_ver.save()

    send_title = ''
    send_body = ''

    if send_type == 'register':
        send_title = '欢迎注册尚在线教育:'
        send_body = '请点击下面链接进行激活\n http://127.0.0.1:8000/users/active/' + code
        send_mail(send_title, send_body, EMAIL_FROM, [email])

    if send_type == 'forget':
        send_title = '尚在线重置密码功能:'
        send_body = '请点击下面链接进行重置密码\n http://127.0.0.1:8000/users/user_reset/' + code
        send_mail(send_title, send_body, EMAIL_FROM, [email])

    if send_type == 'changeemail':
        send_title = '尚在线修改邮箱功能:'
        send_body = '您的验证码是:' + code
        send_mail(send_title, send_body, EMAIL_FROM, [email])
示例#10
0
def send_email_verify(email,send_type):
    code = get_random_code()
    if send_type == 'change':
        code = get_random_code(4)
    email_ver = EmailVerify()
    email_ver.email = email
    email_ver.send_type = send_type
    email_ver.code = code
    email_ver.save()
    if send_type == 'captcha':
        send_title = '欢迎注册:'
        send_body = '请输入你的验证码,你的验证码是:'+code
        send_mail(send_title,send_body,EMAIL_FROM,[email])
def send_email_verify(email):
    code = get_random_code()
    email_ver = EmailVerify()
    email_ver.email = email
    email_ver.code = code
    email_ver.save()

    send_title = '欢迎实名认证尚众筹'
    send_body = '您的验证码为' + code + ',请尽快输入以完成验证'

    send_mail(send_title, send_body, EMAIL_FORM, [email])
示例#12
0
    def test_emailverify_saving_and_retrieving_from_db(self):
        register_code = EmailVerify(
            code="123456",
            email="*****@*****.**",
            verify_type="register",
            send_time=timezone.now(),
        )
        forget_code = EmailVerify(
            code="654321",
            email="*****@*****.**",
            verify_type="forget",
            send_time=timezone.now(),
        )
        register_code.save()
        forget_code.save()

        codes = EmailVerify.objects.all()
        self.assertEqual(codes.count(), 2)
        self.assertEqual(codes[0].code, register_code.code)
        self.assertEqual(codes[1].code, forget_code.code)
示例#13
0
def send_register_email(email, send_type="register"):
    email_record = EmailVerify()
    if send_type == "update":
        code = random_str(4)
    else:
        code = random_str(16)
    email_record.code = code
    print("")
    print(code)
    print("")
    email_record.email = email
    email_record.send_type = send_type
    email_record.save()

    email_title = ""
    email_body = ""

    if send_type == "register":
        email_title = "慕学在线"
        email_body = "click  the link http:\\localhost:8000\\active\\{0}   to active you account".format(
            code)

        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        if send_status:
            pass
    elif send_type == "forget":
        email_title = "慕学在线"
        email_body = "click  the link http:\\localhost:8000\\resetpwd\\{0} to recover your password ".format(
            code)

        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        if send_status:
            pass
    elif send_type == "update":
        email_title = "慕学在线"
        email_body = "click  the link http:\\localhost:8000\\resetpwd\\{0} to update your password ".format(
            code)

        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        if send_status:
            pass
示例#14
0
def send_email_code(email, send_type="register"):
    # 保存数据到数据库
    if send_type == "modify":
        code = generate_digits_code(length=6)
    else:
        code = generate_code(length=64)
    EmailVerify(email=email, code=code, send_type=send_type).save()

    # 发送邮件
    if send_type == "register":
        subject = "用户账号激活邮件"
        content = "请点击以下链接激活你的账号:{0}/active/{1}".format(
            settings.CUSTOM_DNS, code)
    elif send_type == "forget":
        subject = "用户密码重置邮件"
        content = "请点击以下链接重置你的账号密码:{0}/email_reset_password/{1}".format(
            settings.CUSTOM_DNS, code)
    elif send_type == "modify":
        subject = "更改用户邮箱邮件"
        content = "您的邮箱验证码为:{0}".format(code)
    else:
        return "无效的send_type:{0}".format(send_type)

    return send_mail(subject, content, EMAIL_HOST_USER, [email])
示例#15
0
def send_email_verify(email, send_type):
    code = get_code()
    if send_type == 'changeemail':
        code = get_code(4)
    email_ver = EmailVerify()
    email_ver.email = email
    email_ver.code = code
    email_ver.send_type = send_type
    email_ver.save()

    if send_type == 'register':
        send_title = '欢迎注册尚在线教育:'
        send_body = '请点以下链接以激活\n http://127.0.0.1:8000/users/active/' + code
        send_mail(send_title, send_body, EMAIL_FROM, [email])

    if send_type == 'forget':
        send_title = '欢迎登录尚在线教育'
        send_body = '请点以下链接以更改密码\n http://127.0.0.1:8000/users/reset/' + code + '/' + email
        send_mail(send_title, send_body, EMAIL_FROM, [email])

    if send_type == 'changeemail':
        send_title = '欢迎更改邮箱'
        send_body = '请复制以下验证码到更改框中:\n ' + code
        send_mail(send_title, send_body, EMAIL_FROM, [email])