Example #1
0
def request():
    form = Account_Request()
    if form.validate_on_submit():

        email = form.email.data
        #Need to check that the email domain provided is valid

        #This check prevents the user from requesting accounts with the same information.
        #Email should be used as unique identifier in LDAP Directory
        #Use switch for active vs archived vs absent
        account_status = helpers.check_exists_or_archived(current_user.email)
        if account_status['exists'] == True:
            returned = {}
            returned[
                'return_message'] = 'An account with this email address has already been created. You may check the username using the form below.'
            returned['return_category'] = 'error'
            flash(returned['return_message'],
                  category=returned['return_category'])
            return redirect(url_for('finduser'))

        token = helpers.generate_confirmation_token(email)
        confirm_url = url_for('confirm_email', token=token, _external=True)

        #This message should be sent as an email
        message = 'Please check your %s mailbox for a confirmation email. Validation link: %s ' % (
            email, confirm_url)
        category = 'success'
        flash(message, category=category)

    return render_template('request.html',
                           title='Accounts - Account Creation',
                           form=form)
Example #2
0
def pwreset():
    form = FindUser()
    if form.validate_on_submit():

        email = form.email.data

        account_status = helpers.check_exists_or_archived(email)

        #use case here
        if account_status['archived']:
            message = 'This account has been archived, and the password cannot be reset. Please contact your Systems Administrator'
            category = 'error'
        elif account_status['exists']:
            token = helpers.generate_confirmation_token(email)
            confirm_url = url_for('pwreset_confirm_email',
                                  token=token,
                                  _external=True)

            #This message should be sent as an email
            message = 'Please check your %s mailbox for a confirmation email. Validation link: %s ' % (
                email, confirm_url)
            category = 'success'
        else:
            message = 'An account could not be found for the email provided.'
            category = 'error'

        flash(message, category=category)
        return render_template('pwreset.html',
                               title='Accounts - Reset Password',
                               form=form)

    return render_template('pwreset.html',
                           title='Accounts - Reset Password',
                           form=form)
Example #3
0
def pwreset():
    form = FindUser()
    form.validate_on_submit()

    if form.validate_on_submit():

        uin = form.uin.data
        email = form.oduemail.data

        status = helpers.check_exists_or_archived(uin=uin, email=email)

        if status['archived']:
            message = 'This CS Account has been archived, and the password cannot be reset. Please contact [email protected].'
            category = 'error'
        elif status['exists']:
            token = helpers.generate_confirmation_token(uin)
            confirm_url = url_for('pwreset_confirm_email',
                                  token=token,
                                  _external=True)
            message = 'Please check your %s mailbox for a confirmation email. Validation link: %s ' % (
                email, confirm_url)
            category = 'success'
        else:
            message = 'An Account could not be found for this Email/UIN Combination.'
            category = 'error'

        flash(message, category=category)
        return render_template('pwreset.html',
                               title='Accounts - Reset Password',
                               form=form)

    return render_template('pwreset.html',
                           title='Accounts - Reset Password',
                           form=form)
Example #4
0
def request():
    form = Account_Request()
    form.validate_on_submit()
    if form.validate_on_submit():

        uin = form.uin.data
        email = form.oduemail.data

        email_filter = EnrollFile.email == email
        uin_filter = EnrollFile.uin == uin

        #This check prevents the user from requesting accounts with the same information.
        user = EnrollFile.query.filter_by(email=email).first()
        exists_status = helpers.check_exists_or_archived(uin=user.uin,
                                                         email=user.email)
        if exists_status['exists'] == True:
            returned = {}
            returned[
                'return_message'] = 'An account with this information has already been created. You may check the username using the form below.'
            returned['return_category'] = 'error'
            flash(returned['return_message'],
                  category=returned['return_category'])
            return redirect(url_for('finduser'))

        #confirm that the user is in the database/enroll file.
        if db.session.query(EnrollFile).filter(uin_filter,
                                               email_filter).count() >= 1:

            token = helpers.generate_confirmation_token(email)
            confirm_url = url_for('confirm_email', token=token, _external=True)
            message = 'Please check your %s mailbox for a confirmation email. Validation link: %s ' % (
                email, confirm_url)
            category = 'success'
            flash(message, category=category)
        else:
            message = 'You are not eligible for a CS Account. Please ensure that you are enrolled in a CS Course, and that you have entered your MIDAS email and your UIN correctly.'
            category = 'error'
            flash(message, category=category)

    return render_template('request.html',
                           title='Accounts - Account Creation',
                           form=form)
Example #5
0
def confirm_email(token):

    form = PWChoose()

    #This code will only run if no info has been entered in the form.
    #Confirm that a valid token as been GET'd. If the token is valid, render the password input screen.
    email = helpers.confirm_token(token)

    #This check prevents the user from double-opening the validation link to create multiple accounts.
    exists_status = helpers.check_exists_or_archived(email)
    if exists_status['exists'] == True:
        returned = {}
        returned[
            'return_message'] = 'An account with this information has already been created. You may check the username using the form below.'
        returned['return_category'] = 'error'
        flash(returned['return_message'], category=returned['return_category'])
        return redirect(url_for('finduser'))

    if email:
        return render_template('pwchoose.html',
                               title='Accounts - Choose Account Password',
                               form=form)
    else:
        message = 'You do not have a valid token. It either doesn\'t exist or has expired. You may request an account using this form.'
        category = 'error'
        flash(message, category=category)
        return redirect(url_for('request'))

    #This code will only run if the page has proper info POST'd to it.
    #Check the password complexity, and then create the account. If password isnt
    # complex enough, flash a warning to re-enter a password.
    if form.validate_on_submit():

        #Pull their email address from the token
        email = helpers.confirm_token(token)

        #Need to pull user details from form as opposed to relying on enrollfile
        #user = EnrollFile.query.filter_by(email=email).first()

        samaccountname = helpers.determine_username(user.email, user.firstname,
                                                    user.lastname)

        #Check the password for complexity errors. If found, re-prompt at display the errors.
        error_dict = helpers.password_check(form.pw.data, user.firstname,
                                            user.lastname, samaccountname)

        if error_dict['password_ok'] == False:

            returned = {}
            returned[
                'return_message'] = 'Complexity error, please re-enter password: '******'password_ok':
                    continue
                if error_dict[key] == True:
                    returned['return_category'] = 'error'
                    returned['return_message'] += '-' + key + '-'

            flash(returned['return_message'],
                  category=returned['return_category'])
            return render_template('pwchoose.html',
                                   title='Accounts - Choose Account Password',
                                   form=form)

        #After checking the account password, we can finally move on to initiating the account creation.
        returned = helpers.create_account(user.firstname,
                                          user.lastname,
                                          user.uin,
                                          user.email,
                                          user.grad,
                                          samaccountname=samaccountname)

        if returned['return_category'] == 'success':
            #We should output their username to the browser when we redirect back to login as well as send a final email
            flash(returned['return_message'],
                  category=returned['return_category'])
            return redirect(url_for('login'))
        else:
            returned[
                'return_message'] = 'A creation error has occured when attempting to create your account. Please contact your Systems Administrator and take note of the time of this error.'
            returned['return_category'] = 'error'
            flash(returned['return_message'],
                  category=returned['return_category'])
            return redirect(url_for('login'))