Exemplo n.º 1
0
def send_recovery_email(request):
    """
    This function generates an email with a URL link that allows the user to perform a password recovery and reset.
    """
    class PasswordRecoveryForm(forms.Form):
        username = forms.CharField(label='Enter your username:'******'^[a-zA-Z0-9]*$', message='Invalid username', code='invalid_username')])

    try:
        if request.method == 'GET':
            form = PasswordRecoveryForm()    
            return render(request, 'ss/recover.html', {'form': form})

        elif request.method == 'POST':
            form = PasswordRecoveryForm(request.POST)    

        if form.is_valid():
            username = form.cleaned_data.get('username')
            email, token = utils.set_token(ldap_host, ldap_admin, ldap_cred, ldap_dn, username, ldap_user_group)
            subject = 'Password Recovery'
            full_path = request.get_full_path()
            parsed_url = urlparse.urlparse(full_path)

            pathparts = str.split(str(parsed_url.path),'/')
            baseurl = '/'.join(pathparts)

            token_timeout = token_timeout_min
            token_timeout_units = 'minutes'

            if (token_timeout_min > 60):
                token_timeout = token_timeout_min/60
                token_timeout_units = 'hours'

            message = '''
A request to recover your password has been received.
If you did not request this, please contact the administrators of the system.
If you did, you can complete the recovery process by clicking on the following link...
https://%s%s%s

This link will expire within %d %s.
            ''' % (request.get_host(), baseurl, token, token_timeout, token_timeout_units)
            log.error(message)

            #IF DEBUG, COMMENT OUT NEXT LINE
            #utils.send_email(email_server, email_port, email_local_hostname, email_username, email_password, email, email_fromaddr, subject, message)

            content = '''
Sent to email address associated with user, %s.

NOTE: The link in the email will expire in %d %s.
            ''' % (username, token_timeout, token_timeout_units)
            return render(request, 'ss/email_success.html', {'content': content})

    except Exception as e:
       log.exception(e)
       url = request.get_full_path()
       return render(request, 'ss/error.html', {'content': e, 'url': url})

    return render(request, 'ss/recover.html', {'form': form})
Exemplo n.º 2
0
def send_recovery_email(request):
"""
This function generates an email with a URL link that allows the user to perform a password recovery and reset.
"""
    class PasswordRecoveryForm(forms.Form):
        username = forms.CharField(label='Enter your username:'******'^[a-zA-Z0-9]*$', message='Invalid username', code='invalid_username')])

    try:
        if request.method == 'GET':
            form = PasswordRecoveryForm()    
	    return render(request, 'ss/recover.html', {'form': form})

        elif request.method == 'POST':
            form = PasswordRecoveryForm(request.POST)    

	    if form.is_valid():
                username = form.cleaned_data.get('username')
                email, token = utils.set_token(ldap_host, ldap_admin, ldap_cred, ldap_dn, username)
                subject = 'Password Recovery'
                full_path = request.get_full_path()
                parsed_url = urlparse.urlparse(full_path)

                pathparts = str.split(str(parsed_url.path),'/')                

                pathparts = pathparts[0:len(pathparts)-1]
                baseurl = '/'.join(pathparts) 
             
                #basepath = '/'.join(pathparts) 
                #baseurl = '%s://%s/%s' % (urlparts.scheme, urlparts.netloc, basepath)
                # RLJ TODO, hardcoded the https since behind a proxy with only 
                # https, need to learn how to interrogate the request to learn
                # if behind proxy.
                message = '''
A request to recover your password has been received.
If you did not request this, please contact the administrators of the system.
If you did, you can complete the recovery process by clicking on the following link...
https://%s%s/%s/ 
    	        ''' % (request.get_host(), baseurl, token)
                utils.send_email(email_server, email_port, email_local_hostname, email_username, email_password, email, email_fromaddr, subject, message)
                content = 'Sent to email address associated with user, %s.' % username
		return render(request, 'ss/email_success.html', {'content': content})

    except Exception as e:
       log.error(e)
       url = request.get_full_path()
       return render(request, 'ss/error.html', {'content': e, 'url': url})

    return render(request, 'ss/recover.html', {'form': form})
Exemplo n.º 3
0
# -*- coding: utf-8 -*-
from utils import get_auth_url_and_token, set_token

url, token = get_auth_url_and_token()

print "LOGIN INTO THE URL OD ROPBOX:", url

raw_input()

set_token(token)