Example #1
0
def login_confirm():

	form = LoginForm()
	the_hash = '' #the good stuff

	if request.method == 'POST':
		user = User()
		user_set = User.objects(username=normalize_from_unicode(form.username.data))
		print("VALIDATING EXISTANCE HOLD ON")
		if not user_set:
			print("Something has gone horribly wrong")#TERMINATE EXECUTION HERE, Non-Existant user
			flash('Invalid user!')
			return redirect(url_for('login'))
		else:
			user = user_set[0]
			print("USERNAME")
			print(user.username)
			the_hash = user.hashed_pass#Retrieve the hashed_pass, user exists

	if validate_login(normalize_from_unicode(form.password.data), normalize_from_unicode(the_hash), user):#determine if the login is correct!
		login_user(user, remember='no')
		flash("Logged in successfully", category='success')
		return render_template('success.html')

	flash("Wrong username or password", category='error')

	return(render_template('login.html', form))
Example #2
0
def login_confirm():

    form = LoginForm()
    the_hash = ''  #the good stuff

    if request.method == 'POST':
        user = User()
        user_set = User.objects(
            username=normalize_from_unicode(form.username.data))
        print("VALIDATING EXISTANCE HOLD ON")
        if not user_set:
            print("Something has gone horribly wrong"
                  )  #TERMINATE EXECUTION HERE, Non-Existant user
            flash('Invalid user!')
            return redirect(url_for('login'))
        else:
            user = user_set[0]
            print("USERNAME")
            print(user.username)
            the_hash = user.hashed_pass  #Retrieve the hashed_pass, user exists

    if validate_login(normalize_from_unicode(form.password.data),
                      normalize_from_unicode(the_hash),
                      user):  #determine if the login is correct!
        login_user(user, remember='no')
        flash("Logged in successfully", category='success')
        return render_template('success.html')

    flash("Wrong username or password", category='error')

    return (render_template('login.html', form))
Example #3
0
def register_confirm():
    form = RegisterForm()
    normalized_pass = normalize_from_unicode(form.new_password.data)
    new_user = User()

    normalized_name = normalize_from_unicode(form.new_username.data)

    new_user.username = form.new_username.data
    new_user.email = form.new_email.data
    new_user.hashed_pass = hashpw(normalized_pass, gensalt())
    new_user.save(
    )  #Save the user after populating it with the new information

    does_user_exist_now = User.objects(username=normalized_name)
    retrieved_name = ''
    if not does_user_exist_now:
        print("CATASTROPHIC ERROR")
        return redirect('registration.html',
                        title='title',
                        form=RegisterForm())
    else:
        unicode_vessel = normalize_from_unicode(
            does_user_exist_now[0].username)
        retrieved_name = unicode_vessel
        login_user(new_user, remember='no')
        flash("Logged in for the first time!", category='success')

    #Begin bad validation
    user = {'nickname': retrieved_name}  #display a new name!
    posts = [{
        'author': {
            'nickname': 'John'
        },
        'body': 'Beautiful day in portland!'
    }, {
        'author': {
            'nickname': 'Susan'
        },
        'body': 'The Avengers movie was so cool! Shame about BvS!'
    }]
    #End bad validation
    return render_template('index.html',
                           title='LoggedIn',
                           user=user,
                           post=posts)
Example #4
0
def register_confirm():
	form = RegisterForm()
	normalized_pass = normalize_from_unicode(form.new_password.data)
	new_user = User()

	normalized_name = normalize_from_unicode(form.new_username.data)

	new_user.username = form.new_username.data
	new_user.email = form.new_email.data
	new_user.hashed_pass = hashpw(normalized_pass, gensalt())
	new_user.save()#Save the user after populating it with the new information

	does_user_exist_now = User.objects(username=normalized_name)
	retrieved_name = ''
	if not does_user_exist_now:
		print("CATASTROPHIC ERROR")
		return redirect('registration.html', title='title', form=RegisterForm())
	else:
		unicode_vessel = normalize_from_unicode(does_user_exist_now[0].username)
		retrieved_name = unicode_vessel
		login_user(new_user, remember='no')
		flash("Logged in for the first time!", category='success')

	#Begin bad validation
	user = {'nickname': retrieved_name} #display a new name!
	posts = [
		{
			'author': {'nickname': 'John'},
			'body':	'Beautiful day in portland!'
		},

		{
			'author': {'nickname': 'Susan'},
			'body': 'The Avengers movie was so cool! Shame about BvS!'
		}
	]
	#End bad validation
	return render_template('index.html', title='LoggedIn', user=user, post=posts)
Example #5
0
	def get_id(self):
		try:
			return unicode(self.username)
		except NameError:
			return normalize_from_unicode(self.username)
Example #6
0
 def get_id(self):
     try:
         return unicode(self.username)
     except NameError:
         return normalize_from_unicode(self.username)