Exemple #1
0
def register_post( request ):
    '''
    @summary: post register form
    '''
    assert request.method == 'POST'
    form = RegisterForm( request.POST )
    if form.is_valid():
        # get cleaned data
        cd = form.cleaned_data
        user = User.objects.create_user( username = cd['email'], email = cd['email'], password = cd['passwd1'] )
        user.first_name = cd['nickName']
        user.is_active = False
        user.save()
        
        link = 'http://' + request.get_host() + '/accounts/validate/'
        link += '?id=' + str( user.id ) + '&token=' + genValiStr( cd['email'] )


        # mail port is forbidden in BAE
        # content = u'亲爱的用户' + cd['nickName'] + u':\n'
        # content += u'    请点击以下链接来验证您的 God Notes 电子邮箱地址:\n'
        # content += link
        # send_mail( u'God Notes 账户激活', content ,
        #           '*****@*****.**', [cd['email']], fail_silently = False )
        # return render( request, 'accounts/info.html', {'status':'validating', 'email':cd['email']} )


        # now directly redirect to activation page
        return redirect( link )
    return render( request, "accounts/register.html", { 'form':form} )
Exemple #2
0
def validate( request ):
    if request.method == 'GET' and request.GET.get( 'id', '' ) and request.GET.get( 'token', '' ):
        try:
            id = int( request.GET['id'] )
            user = User.objects.get( id = id )
            if genValiStr( user.email ) == request.GET['token']:
                user.is_active = True
                user.save()
                message = '验证成功,<a href="/accounts/login/">点此</a>登录。'
        except:
            message = '验证失败,请重新<a href="/accounts/register/">注册</a>。'
            pass
    return render( request, 'info.html', locals() )