Exemplo n.º 1
0
def edit_account(user_id):
    form = EditAccountForm(request.form)
    if not session.get('logged_in'):
        return "You are not logged in"
    user = dbOps.get_user_by_ID(user_id)
    if not user:
        return "No user account associated with that user"
    if request.method == 'GET':
        return render_template("edit_account_page.html", user_id=user_id, form=form)
    if request.method == 'POST' and form.validate():
        errors = []
        new_email = form.email.data
        new_pword = form.password.data
        if (not new_email) and (not new_pword):
            errors += ['Please enter a new email or password']
        errors += validate_password(new_pword) + validate_email(new_email)
        if dbOps.user_exists(new_email):
            flash("Account already exists for this email")
            return render_template("edit_account_page.html", user_id=user_id, form=form)
        if len(errors) is not 0:
            if errors[0] !='field is required':
                flash(errors[0])
                return render_template("edit_account_page.html", user_id=user_id, form=form)
        if new_email:
            dbOps.send_verification_email(new_email, mail_manager)
            flash("you will receive a confirmation email with an activation URL, to prove that the new email address belongs to you")
            dbOps.edit_user_account(user_id, new_email, encrypt(new_pword))
            return redirect(url_for('index'))
        dbOps.edit_user_account(user_id, new_email, encrypt(new_pword))
        flash("Account successfully updated")
        return redirect(url_for('show_user_page', user_id=user_id))
    else:
        flash("Please fix any errors")
        return render_template("edit_account_page.html", user_id=user_id, form=form)
Exemplo n.º 2
0
 def activate_user(email):
     valid_email = len(validate_email(email)) == 0
     if (valid_email):
         try:
             user_document = User.objects.get(email=email)
             user_document.activated = True
             user_document.save()
             return True
         except:
             print "Error occurred trying to activate user for email = " + email
     return False
Exemplo n.º 3
0
 def activate_user(email):
     valid_email = len(validate_email(email)) == 0
     if (valid_email):
         try:
             user_document = User.objects.get(email=email)
             user_document.activated = True
             user_document.save()
             return True
         except:
             print "Error occurred trying to activate user for email = " + email
     return False
Exemplo n.º 4
0
def edit_account(user_id):
    form = EditAccountForm(request.form)
    if not session.get('logged_in'):
        return "You are not logged in"
    user = dbOps.get_user_by_ID(user_id)
    if not user:
        return "No user account associated with that user"
    if request.method == 'GET':
        return render_template("edit_account_page.html",
                               user_id=user_id,
                               form=form)
    if request.method == 'POST' and form.validate():
        errors = []
        new_email = form.email.data
        new_pword = form.password.data
        if (not new_email) and (not new_pword):
            errors += ['Please enter a new email or password']
        errors += validate_password(new_pword) + validate_email(new_email)
        if dbOps.user_exists(new_email):
            flash("Account already exists for this email")
            return render_template("edit_account_page.html",
                                   user_id=user_id,
                                   form=form)
        if len(errors) is not 0:
            if errors[0] != 'field is required':
                flash(errors[0])
                return render_template("edit_account_page.html",
                                       user_id=user_id,
                                       form=form)
        if new_email:
            dbOps.send_verification_email(new_email, mail_manager)
            flash(
                "you will receive a confirmation email with an activation URL, to prove that the new email address belongs to you"
            )
            dbOps.edit_user_account(user_id, new_email, encrypt(new_pword))
            return redirect(url_for('index'))
        dbOps.edit_user_account(user_id, new_email, encrypt(new_pword))
        flash("Account successfully updated")
        return redirect(url_for('show_user_page', user_id=user_id))
    else:
        flash("Please fix any errors")
        return render_template("edit_account_page.html",
                               user_id=user_id,
                               form=form)
Exemplo n.º 5
0
def create_post():
    if not session.get('logged_in'):
        return 'You are not logged in'
    user_id = request.values['user_id']
    if request.method == 'GET':
        return render_template("create_post_page.html", user_id=session['user_id'])
    else:
        title = request.values['textbook_title']
        author = request.values['textbook_author']
        email = request.values['contact_seller_email']
        if email and validate_email(email) is None:
            flash("Email address is not valid")
            return render_template("create_post_page.html")
        if not title:
            flash("You need to submit a title for the book")
            return render_template("create_post_page.html")

        newpost = dbOps.insert_post(title, user_id, author, email)
        return redirect(url_for('show_post', post_id=newpost.post_id, user_id=session['user_id']))
Exemplo n.º 6
0
def create_account():
    errors = []
    password = request.form['password']
    email = request.form['email']
    if request.method == 'POST':
        errors = validate_password(password)
        email_errors = validate_email(email)
        if len(email_errors) is not 0:
            errors.append(email_errors)

    if len(errors) is 0:
        if dbOps.user_exists(email):
            flash("Account already exists for this email")
            return render_template('signup.html', error=errors)
        else:
            dbOps.insert_user(email, encrypt(password))
            dbOps.send_verification_email(email, mail_manager)
            return render_template('index.html')
    else:
        formatted_error = '. '.join(str(error) for error in errors)
        flash(formatted_error)
        return render_template('signup.html')
Exemplo n.º 7
0
def create_account():
    errors = []
    password = request.form['password']
    email = request.form['email']
    if request.method == 'POST':
        errors = validate_password(password)
        email_errors = validate_email(email)
        if len(email_errors) is not 0:
            errors.append(email_errors)

    if len(errors) is 0:
        if dbOps.user_exists(email):
            flash("Account already exists for this email")
            return render_template('signup.html', error=errors)
        else:
            dbOps.insert_user(email, encrypt(password))
            dbOps.send_verification_email(email, mail_manager)
            return render_template('index.html')
    else:
        formatted_error = '. '.join(str(error) for error in errors)
        flash(formatted_error)
        return render_template('signup.html')
Exemplo n.º 8
0
def create_post():
    if not session.get('logged_in'):
        return 'You are not logged in'
    user_id = request.values['user_id']
    if request.method == 'GET':
        return render_template("create_post_page.html",
                               user_id=session['user_id'])
    else:
        title = request.values['textbook_title']
        author = request.values['textbook_author']
        email = request.values['contact_seller_email']
        if email and validate_email(email) is None:
            flash("Email address is not valid")
            return render_template("create_post_page.html")
        if not title:
            flash("You need to submit a title for the book")
            return render_template("create_post_page.html")

        newpost = dbOps.insert_post(title, user_id, author, email)
        return redirect(
            url_for('show_post',
                    post_id=newpost.post_id,
                    user_id=session['user_id']))
 def test_null(self):
     self.assertEquals(validate_email(""), ['field is required'])
     self.assertEquals(validate_email(None), ['field is required'])
 def test_syntax(self):
     self.assertEquals(validate_email("*****@*****.**"), [])
     self.assertEqual(validate_email('[email protected]'), ['The email address submitted is invalid'])