Exemplo n.º 1
0
        def decorated_function(*args, **kwargs):
            user = User.find_by_email(email=session['email'])
            if user.role not in roles:
                flash('You do not have permission to do that.', 'error')
                return redirect('/')

            return f(*args, **kwargs)
Exemplo n.º 2
0
def mail_verification():
    email = session['email']
    user = User.find_by_email(email=email)
    mail_verification = user.serialize_token()
    deliver_mail_verification_email(email=email,
                                    mail_verification=mail_verification)
    return redirect(url_for('home_page'))
Exemplo n.º 3
0
def update_profile(user_id):
    if request.method == "POST":
        name = request.form['name']
        lastname = request.form['lastname']
        province = request.form['province']
        district = request.form['district']
        sub_district = request.form['sub_district']
        salary = request.form['salary']

        user = User.find_by_email(session['email'])
        user.name = name
        user.lastname = lastname
        user.province = province
        user.district = district
        user.sub_district = sub_district
        user.salary = salary

        user.save_to_mongo()

        return redirect(url_for('home.index'))


    return render_template('users/profile.html', user=User.find_by_email(session['email']))
Exemplo n.º 4
0
def deliver_password_reset_email(email, reset_token):

    user = User.find_by_email(email=email)
    try:
        ctx = {'user': user, 'reset_token': reset_token}

        send_template_message(subject='REDFI Password reset',
                              recipients=[email],
                              template='mail/password_reset',
                              ctx=ctx)
    except Exception:
        raise UserErrors.InvalidEmailError(
            "Can't validate the email address provided. Make sure email is correct or try after sometime."
        )
    return None
Exemplo n.º 5
0
def deliver_mail_verification_email(email, mail_verification):

    user = User.find_by_email(email=email)
    try:
        ctx = {'user': user, 'mail_verification': mail_verification}

        send_template_message(subject='REDFI E-mail Verification',
                              recipients=[email],
                              template='mail/mail_verification',
                              ctx=ctx)
    except Exception:
        raise UserErrors.InvalidEmailError(
            "Can't validate the email address provided. Make sure email is correct or try after sometime."
        )
    return None
Exemplo n.º 6
0
def password_reset_trigger():
    form = PasswordResetTriggerForm()

    if form.validate_on_submit():
        email = form.email.data
        try:
            user = User.find_by_email(email=email)
            reset_token = user.serialize_token()
            from models.user.tasks import deliver_password_reset_email
            deliver_password_reset_email(email, reset_token)
            flash('A password rest link has been sent to {0}.'.format(email),
                  'success')
            return redirect(url_for('users.login_user'))
        except UserErrors.UserError as e:
            flash(e.message, 'danger')
    return render_template('password_reset_trigger.html', form=form)
Exemplo n.º 7
0
def login_user():
    session.permanent = True
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        try:
            if User.is_login_valid(email, password):
                session['email'] = email
                return redirect(url_for('home.index'))
        except UserErrors.UserError as e:
            return render_template("users/login.html", message = e.message) 
    try:
        if  User.find_by_email(session['email']):
            return redirect(url_for('home.index'))
    except:
        pass


    return render_template("users/login.html")  # Send the user an error if their login was invalid
Exemplo n.º 8
0
def register_user():
    if request.method == 'POST':
        name = request.form['name']
        lastname = request.form['lastname']
        email = request.form['email']
        password = request.form['password']

        try:
            if User.register_user(name, lastname, email, password):
                session['email'] = email
                return redirect(url_for('home.index'))
        except UserErrors.UserError as e:
            return e.message
    
    try:
        if  User.find_by_email(session['email']):
            return redirect(url_for('home.index'))
    except:
        pass


    return render_template("users/register.html")  # Send the user an error if their login was invalid
Exemplo n.º 9
0
 def __post_init__(self):
     self.item = Item.get_by_id(self.item_id)
     self.user = User.find_by_email(self.user_email)
Exemplo n.º 10
0
 def __post_init__(self) -> None:
     self.item = Item.fetch_by_id(self.item_id)
     self.user = User.find_by_email(self.user_email)