Beispiel #1
0
def profile_settings_password(user):

    user_account_update = user_account.profile_acc_update(current_user.info_id)

    form = PasswordUpdateForm()

    if form.validate_on_submit():

        user = user_account.login(
            [current_user.username, form.oldpassword.data])

        if user:

            user_account_update.password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')

            db.session.commit()

            flash('Password was successfully updated!', 'success')

            return redirect(
                url_for('linkages.profile_settings_password',
                        user=current_user.username))

        else:

            flash('Wrong password.', 'error')

    return render_template('/linkages/profile/settings/password.html',
                           title="Linkages",
                           form=form)
Beispiel #2
0
def profile_settings_username(user):

    user_account_update = user_account.profile_acc_update(current_user.info_id)

    form = ProfileUsernameUpdateForm()

    if form.validate_on_submit():

        user = user_account.login(
            [current_user.username, form.oldpassword.data])

        if user:

            user_account_update.username = form.username.data

            db.session.commit()

            flash('Username was successfully updated!', 'success')

            return redirect(
                url_for('linkages.profile_settings_username',
                        user=current_user.username))

        else:

            flash('Wrong password.', 'error')

    else:

        form.username.data = user_account_update.username

    return render_template('/linkages/profile/settings/username.html',
                           title="Linkages",
                           form=form)
Beispiel #3
0
def login():

	form = LoginForm()

	if form.validate_on_submit():
        
		user = user_account.login([form.username.data, form.password.data])

		if user is None:
			flash('Invalid username or password', 'error')
			return redirect(url_for('unregistered.login'))

		if user.status != "A":

			if user.status=="P":
				flash('MOA not yet acknowledged. Please check your email.', 'info')
			else:
				flash('Inactive account. Please contact the Re-COP Director.', 'error')
			
			return redirect(url_for('unregistered.login'))

		login_user(user, remember=form.remember_me.data)

		name = user_views.login_info(current_user.id)

		if current_user.type==3:
			name = name.company_name
		elif current_user.type==4:
			name = name.address			
		else:
			name = name.first_name
			
		flash('Welcome ' + name + '!', 'success')

		if current_user.type == 1:
			return redirect(url_for('admin.index'))	
		elif current_user.type == 2:
			return redirect(url_for('registered.index'))
		elif current_user.type == 3:
			return redirect(url_for('linkages.index'))
		elif current_user.type == 4:
			return redirect(url_for('communities.index'))
		elif current_user.type == 5:
			return redirect(url_for('religious_admin.index'))	
	
	return render_template('/unregistered/login/index.html', form=form)
Beispiel #4
0
def event_signing(token, action):

	id = confirm(token)

	if id=='bad':
		flash('Link already expired. Please contact the ReCOP Administrator.', 'error')
		return redirect(url_for('unregistered.index'))

	event = event_views.show_info(id)
	organizer = user_information.linkage_info(event.organizer_id)
	success = user_account.retrieve_user(event.organizer_id)

	form = LoginForm()

	if form.validate_on_submit():

		user = user_account.login([form.username.data, form.password.data])

		if user and user.type==5:

			if action=='approve':

				if event.status=='A':
					if user.id==4:
						signatory = user_views.signatory_info(3)
						status='F'
					else:
						flash('Invalid credentials! Please try again.', 'error')	
						return redirect(url_for('unregistered.event_signing', token=token, action=action))
				elif event.status=='F':
					if user.id==3:
						signatory = user_views.signatory_info(2)
						status='P'
					else:
						flash('Invalid credentials! Please try again.', 'error')	
						return redirect(url_for('unregistered.event_signing', token=token, action=action))
				elif event.status=='P':
					if user.id==2:
						status='S'
						event_information.update_status(event.id, status)
					else:
						flash('Invalid credentials! Please try again.', 'error')
						return redirect(url_for('unregistered.event_signing', token=token, action=action))	

				proposal_tracker.update_status(event.id, status)

				value = [None,user.id,event.id,'event', 5]
				audit_trail.add(value)

				if status!='S':

					recipient = signatory.email_address
					name = 'Fr. ' + signatory.last_name + ', OAR'
					token = generate(event.id)
					approve = url_for('unregistered.event_signing', token=token , action='approve', _external = True)
					decline = url_for('unregistered.event_signing', token=token , action='decline', _external = True)		
					html = render_template('admin/email/event.html', event=event , organizer=organizer.company_name, user=name, link = [approve, decline])
					subject = "NEW EVENT: " + event.name
					attachments = event_attachment.retrieve_files(id)

					email_parts = [html, subject, user.email_address, recipient, attachments]

					send_email(email_parts)

				else:

					recipient = success.email_address
					html = 'Hey ' + success.username + '! Your event entitled ' + event.name.title() + ' was already approved!'
					subject = "NEW EVENT: " + event.name

					email_parts = [html, subject, user.email_address, recipient, None]

					send_email(email_parts)

				flash(event.name.title() + ' was approved!', 'success')
				return redirect('/')

			else:

				if event.status=='A':
					if user.id!=4:
						flash('Invalid credentials! Please try again.', 'error')	
						return redirect(url_for('unregistered.event_signing', token=token, action=action))
				elif event.status=='F':
					if user.id!=3:
						flash('Invalid credentials! Please try again.', 'error')	
						return redirect(url_for('unregistered.event_signing', token=token, action=action))
				elif event.status=='P':
					if user.id!=2:
						flash('Invalid credentials! Please try again.', 'error')
						return redirect(url_for('unregistered.event_signing', token=token, action=action))

				status='X'
				proposal_tracker.update_status(event.id, status)
				event_information.update_status(event.id, status)

				value = [None,user.id,event.id,'event', 6]
				audit_trail.add(value)

				flash(event.name.title() + ' was declined!', 'success')
				return redirect('/')

		else:

			flash('Invalid credentials! Please try again.', 'error')

	return render_template('/unregistered/events/signing.html', form=form, action=action, event=event)