Ejemplo n.º 1
0
def validateRequest(request):
    if dataplus.dictGetVal(request.REQUEST,'username') == '' or dataplus.dictGetVal(request.REQUEST,'name') == '' or dataplus.dictGetVal(request.REQUEST,'email') == '' or dataplus.dictGetVal(request.REQUEST,'password1') == '' or dataplus.dictGetVal(request.REQUEST,'password2') == '':
        return False, errorResponse('All fields are required.', request)
    
    result, errMsg = dataplus.validateErrorConditions(
        [lambda : codejar_validation.validateUsername(dataplus.dictGetVal(request.REQUEST,'username')),
        lambda : codejar_validation.validateName(dataplus.dictGetVal(request.REQUEST,'name')),
        lambda : codejar_validation.validateEmail(dataplus.dictGetVal(request.REQUEST,'email')),
        lambda : dataplus.isLengthValid(dataplus.dictGetVal(request.REQUEST,'password1'), 6, 16, 'Password'),
        lambda : dataplus.isLengthValid(dataplus.dictGetVal(request.REQUEST,'email'), 5, 75, 'Email')
        ])
    if not result:
        return result, errorResponse(errMsg, request)    
    elif dataplus.dictGetVal(request.REQUEST,'password1') != dataplus.dictGetVal(request.REQUEST,'password2'):
        return False, errorResponse('Passwords do not match.', request)
    elif dataplus.dictGetVal(request.REQUEST,'captcha_text') != request.session['signup_captcha_text']:
        return False, errorResponse('The captcha text entered is incorrect.', request)
    else:
        return True, None
Ejemplo n.º 2
0
def validateRequest(request):
    if not dataplus.dictGetVal(request.REQUEST, 'acceptterms', False, lambda x:True):
        return False, errorResponse('Please accept the terms and conditions to continue.',request)
        
    if dataplus.dictGetVal(request.REQUEST,'user-name') == '' or dataplus.dictGetVal(request.REQUEST,'name') == '' or dataplus.dictGetVal(request.REQUEST,'email') == '' or dataplus.dictGetVal(request.REQUEST,'password1') == '' or dataplus.dictGetVal(request.REQUEST,'password2') == '' or dataplus.dictGetVal(request.REQUEST,'country') == '' or dataplus.dictGetVal(request.REQUEST,'industry_category') == '' or dataplus.dictGetVal(request.REQUEST,'experience') == '-1':
        return False, errorResponse('All fields are required.', request)
    
    result, errMsg = dataplus.validateErrorConditions(
        [lambda : codejar_validation.validateName(dataplus.dictGetVal(request.REQUEST,'name')),
        lambda : codejar_validation.validateUsername(dataplus.dictGetVal(request.REQUEST,'user-name')),
        lambda : codejar_validation.validateEmail(dataplus.dictGetVal(request.REQUEST,'email')),
        lambda : dataplus.isLengthValid(dataplus.dictGetVal(request.REQUEST,'password1'), 6, 16, 'Password'),
        lambda : dataplus.isLengthValid(dataplus.dictGetVal(request.REQUEST,'email'), 5, 75, 'Email')
        ])
    if not result:
        return result, errorResponse(errMsg, request)    
    elif dataplus.dictGetVal(request.REQUEST,'password1') != dataplus.dictGetVal(request.REQUEST,'password2'):
        return False, errorResponse('Passwords do not match.', request)
    elif models.Account.objects.filter(username=dataplus.dictGetVal(request.REQUEST, 'user-name')).count() > 0:
        return False, errorResponse('Username already exists. Please choose another.', request)
    else:
        return True, None
Ejemplo n.º 3
0
def handle(request):
    myself = siteaction.getLoggedInAccount(request)
    if not myself:
        return HttpResponseRedirect('/login.htm')

    #TODO: notify user about success, success_page will change
    logged_in_type = siteaction.getLoggedInAccountType(request)
    if logged_in_type == 'U':
        pwd_page = 'me/changepassword.htm'
        success_page = '/me/editsettings.htm?flashId=pwd_chnged'
    elif logged_in_type == 'R':
        pwd_page = 'recruiters/changepassword.htm'    
        success_page = '/recruiters/'
    
    if request.method == 'GET':
        return siteaction.render_to_response(pwd_page, {'myself':myself})

    elif request.method == 'POST':

        #Password length >= 6 and <=12
        valid, invalid_msg = dataplus.isLengthValid(dataplus.dictGetVal(request.REQUEST, 'password1'), 6, 12, 'Password')
        if not valid:
            return siteaction.render_to_response(pwd_page, 
                {'error_html': '<p class="error-note">' + invalid_msg + '</p>'})   
        
        #Passwords should match
        if dataplus.dictGetVal(request.REQUEST, 'password1') != dataplus.dictGetVal(request.REQUEST, 'password2'):
            return siteaction.render_to_response(pwd_page, 
                {'error_html': '<p class="error-note">Passwords do not match.</p>'})
        
        #Is the Old Password Check
        if (siteaction.validatePassword(myself.id, dataplus.dictGetVal(request.REQUEST, 'oldpassword'))):
            myself.password = dataplus.hash(dataplus.dictGetVal(request.REQUEST, 'password1'))
            myself.save()            
            return HttpResponseRedirect(success_page)
        else:
            return siteaction.render_to_response(pwd_page, 
                {'error_html': '<p class="error-note">Old password was incorrect. Try again.</p>'})
Ejemplo n.º 4
0
def handle(request):
    #TODO: Check 24 hour validity period
    passkey = dataplus.dictGetVal(request.REQUEST, 'passwordChangeKey', '')
    change_req = dataplus.returnIfExists(models.PasswordChangeRequest.objects.filter(req_random_key=passkey,created_at__gte=(datetime.datetime.utcnow() - datetime.timedelta(1))))
    if not change_req:
        return siteaction.render_to_response('showmessage.htm', 
            {'msg_heading': 'Password Reset',
             'msg_html': 'Invalid link. The password reset link that you clicked is either invalid or expired. ' + \
                'You can try to <a href="forgotpassword.htm">Reset the Password</a> again.'})
                            
    if request.method == 'GET':
        return siteaction.render_to_response('resetpassword.htm',
        {'passwordChangeKey': dataplus.dictGetVal(request.REQUEST,'passwordChangeKey')})

    elif request.method == 'POST':
        #Password length >= 6 and <=12
        valid, invalid_msg = dataplus.isLengthValid(dataplus.dictGetVal(request.REQUEST,'password1'), 6, 12, 'Password')
        if not valid:
            return siteaction.render_to_response('resetpassword.htm', 
                {'error_html': '<p class="error-note">' + invalid_msg + '</p>',
                 'passwordChangeKey': dataplus.dictGetVal(request.REQUEST,'passwordChangeKey')})   
        
        #Passwords should match
        if dataplus.dictGetVal(request.REQUEST,'password1') != dataplus.dictGetVal(request.REQUEST,'password2'):
            return siteaction.render_to_response('resetpassword.htm', 
                {'error_html': '<p class="error-note">Passwords do not match.</p>',
                 'passwordChangeKey': dataplus.dictGetVal(request.REQUEST,'passwordChangeKey')})

        account = change_req.account
        account.password = dataplus.hash(dataplus.dictGetVal(request.REQUEST,'password1'))
        account.save()
        change_req.delete()
        return siteaction.render_to_response('showmessage.htm', 
            {'msg_heading': 'Password Reset',
             'msg_html': 'Your password was reset. You can now login with your new password. ' + \
                '<a href="/login.htm">Login</a>'})