Example #1
0
def forgot_pass(request):
    module = 'Login'
    page = 'Forgot_Pass'
    args = {}
    args.update(csrf(request))
    if request.method == 'POST':        
        email = request.POST['email']
        per_id= validate_email(email)
## If valid email id, then a mail is sent to his email alongwith a link to reset his password 
        if per_id != -1:     
            args['message']= retrieve_error_message(module,page,'NO_ERR')
            try:
               ec_id = EmailContent.objects.get(systype='Login', name='resetpass').id
            except:
               args['message'] ="Email cannot send at this moment. "
               return render(request,'geterror.html',args)
           #print ec_id
            send_email(request,ec_id, per_id, per_id)
            return render_to_response('login/forgot_pass.html',args)      
                           
        else:
## If invalid email, displays an error message
            args['message']=retrieve_error_message(module,page,'EML_INV')
            return render_to_response('login/forgot_pass.html',args)        
    return render_to_response('login/forgot_pass.html',args)
def forgot_pass(request):
    args = {}
    args.update(csrf(request))
    if request.method == 'POST':
        email = request.POST['email']
        emailid= validate_email(email)
        if emailid != -1:            
            link = 'http://127.0.0.1:9005/resetpass/%d' %emailid
            email_subject = 'Reset Password'
            email_body = "Hey %s,  To Reset your Password, click this link within \
            48hours http://127.0.0.1:9005/resetpass/%d"
            send_mail(email_subject, email_body, '*****@*****.**',[email], fail_silently=False)
            print link
            args['message']=  "We've mailed you the instructions"
            return render_to_response('login/forgot_pass.html',args)                
            #return HttpResponseRedirect('/homepage/')
        else:
            args['message']="Unregistered email"
            return render_to_response('login/forgot_pass.html',args)                
    
    return render_to_response('login/forgot_pass.html',args)