Beispiel #1
0
def login():
    log = current_app.logger

    if current_user.is_authenticated:
        return redirect(url_for('root'))

    form = LoginForm(request.form)
    if form.validate_on_submit():
        log.info('valid form')
        email = form.email.data
        password = form.password.data

        user = get_user(email)
        if not user or not check_password_hash(user.password, password):
            log.info('login failed - wrong login details')
            flash('Please check your login details and try again.')
            return redirect(url_for('auth.login'))
        
        if not user.verified:
            log.info('login failed - user not verified')
            flash('Please check your email and verify your account first!')
            return redirect(url_for('auth.login'))

        log.info('login success')
        login_user(user, remember=True)
        if current_user.is_authenticated:
            return redirect(url_for('root'))

    return render_template('login.html', loginform=form)
Beispiel #2
0
def viewGroup():
    total = []
    err, group = db.get_total_groups(roles.current_id)
    print(group)
    if err == -1:
        return render_template('viewGroupOrder.html', total=total)
    err, order = db.get_orders(roles.current_id)
    print(order)
    if err == -1:
        return render_template('viewGroupOrder.html', total=total)
    for i in range(len(group)):
        group_id = group[i]['id']
        err, members = db.get_group_members(group_id)
        if err == -1:
            continue
        err, admin = db.get_user(group[i]['admin'])
        print(admin)
        if err == -1:
            continue
        print(members)
        entry = {
            'admin': admin[1],
            'shop': order[i]['retail_name'],
            'site': order[i]['retail_link'],
            'location': order[i]['location'],
            'deadline': order[i]['deadline'],
            'num_mem': group[i]['member_count'],
            'members': members
        }
        total.append(entry)
    print(total)
    return render_template('viewGroupOrder.html', total=total)
Beispiel #3
0
def load_user(user_id):
    ''' 
    Take unicode id of user and return corresponding user object
    See https://flask-login.readthedocs.io/en/latest/#how-it-works

    We use email as the user_id
    '''
    return get_user(user_id)
Beispiel #4
0
def request_verification_email():
    form = RequestVerificationEmail(request.form)
    if form.validate_on_submit():
        user = get_user(form.email.data)
        if user:
            send_verification_email(user)
        flash('Link has been sent to your email. It will expire in 24 hours.')
        return redirect(url_for('auth.login'))
    return render_template('verify.html', form=form)
Beispiel #5
0
def verify_account(token):
    email = User.verify_token(token)
    user = get_user(email)
    if user is None:
        flash('Your link has expired or is invalid! Request a new valid link!')
        return redirect(url_for('auth.request_verification_email'))
    user.verified = True
    update_user(user.email, user.to_firestore())
    flash('Account verified! You can now log in')
    return redirect(url_for('auth.login'))
Beispiel #6
0
def handle_user(email):
    if request.method == 'GET':
        user = get_user(email)
        if not user:
            app.logger.error(f"Failed to get user: {email}")
            abort(404, description=f"Failed to get user: {email}")
        return user.to_json()
    if request.method == 'DELETE':
        deleted = delete_user(email)
        if not deleted:
            app.logger.error(f"Failed to delete user: {email}")
            abort(500, f"Failed to delete user: {email}")
        return ('', 204)
Beispiel #7
0
    def retrieve_user(cls, username):
        """
		Retrive a user from database.

		Returns:
		-------
		User object

		Raises:
		------
		UserNotExistsError
			An error raised when failed to retrive a user from database
		"""
        user_detail = dbop.get_user(username)
        return cls(**user_detail)
Beispiel #8
0
 def validate_email(form, email_field):
     user = get_user(email_field.data)
     if user:
         raise ValidationError(
             f'Email {email_field.data} has already been taken, please use another email'
         )