Esempio n. 1
0
def login():
    """
    This view logs in a user given an email address and password.

    This works by querying Stormpath with the user's credentials, and either
    getting back the User object itself, or an exception (in which case well
    tell the user their credentials are invalid).

    If the user is valid, we'll log them in, and store their session for later.
    """
    if request.method == 'GET':
        return render_template('login.html')

    try:
        _user = User.from_login(
            request.form.get('email'),
            request.form.get('password'),
        )
    except StormpathError as err:
        return render_template('login.html',
                               error=err.message,
                               email=request.form.get('email'))

    login_user(_user, remember=True)
    return redirect(request.args.get('next') or url_for('dashboard'))
 def login():
     user = User.from_login(
         request.form.get('email'),
         request.form.get('password'),
     )
     login_user(user, remember=True)
     return 'logged in'
Esempio n. 3
0
def register():
    """
    This view allows a user to register for the site.

    This will create a new User in Stormpath, and then log the user into their
    new account immediately (no email verification required).
    """
    if request.method == 'GET':
        return render_template('register.html')

    try:
        # Create a new Stormpath User.
        _user = stormpath_manager.application.accounts.create({
            'email':
            request.form.get('email'),
            'password':
            request.form.get('password'),
            'given_name':
            'John',
            'surname':
            'Doe',
        })
        _user.__class__ = User
    except StormpathError as err:
        # If something fails, we'll display a user-friendly error message.
        return render_template('register.html',
                               error=err.message,
                               email=request.form.get('email'))

    login_user(_user, remember=True)
    return redirect(url_for('dashboard'))
Esempio n. 4
0
    def test_user_can_login(self):
        _user = User.from_login(
                TestConfig.USER_EMAIL,
                TestConfig.USER_PASSWORD,
            )
        login_user(_user)

        user_id = user.get_id()
        app_user = AppUser.query.get(stormpathUserHash(user_id))
        assert app_user.user_href == user_id
Esempio n. 5
0
    def test_user_can_login(self):
        _user = User.from_login(
            TestConfig.USER_EMAIL,
            TestConfig.USER_PASSWORD,
        )
        login_user(_user)

        user_id = user.get_id()
        app_user = AppUser.query.get(stormpathUserHash(user_id))
        assert app_user.user_href == user_id
Esempio n. 6
0
def login():
    error = None

    if request.method == "POST":
        try:
            _user = User.from_login(request.form["email"], request.form["password"])
            login_user(_user, remember=True)
            flash("Has entrado al sistema.")

            return redirect(url_for("show_posts"))
        except StormpathError, err:
            error = err.message
Esempio n. 7
0
File: CSRF.py Progetto: Rawkcy/CSRF
def login():
    error = None
    if request.method == 'POST':
        try:
            _user = User.from_login(
                request.form['email'],
                request.form['password'],
            )
            login_user(_user, remember=True)
            flash('You were logged in.')
            return redirect(url_for('show_posts'))
        except StormpathError, err:
            error = err.message
Esempio n. 8
0
def login():
	error = None
	try:
		_user = User.from_login(
			request.form['email'],
			request.form['password']
			)

		login_user(_user, remember = True)
		flash('You were logged in.')

		return redirect(url_for('show_posts'))

	except StormpathError, err:
		error = err.message
Esempio n. 9
0
def login():
    error = None

    if request.method == 'POST':
        try:
            _user = User.from_login(
                request.form['email'],
                request.form['password'],
            )
            login_user(_user, remember=True)
            flash('You were logged in.')

            return redirect(url_for('show_posts'))
        except StormpathError as err:
            error = err.message

    return render_template('login.html', error=error)
Esempio n. 10
0
def login():
    error = None
    form = LoginForm()
    if form.validate_on_submit():
        try:
            _user = User.from_login(
                form.email.data,
                form.password.data,
            )
            login_user(_user, remember=True)
            flash('You were logged in.')
            tutnames = db.session.query(Tut.name).all()
            tutnames = [tutname for (tutname, ) in tutnames]
            return redirect(
                url_for('tutorial', tno=g.user.custom_data["tutno"]))
        except StormpathError, err:
            error = err.message
            flash('Please try again')
Esempio n. 11
0
def login():
    """Logs in a user given an email address and password.

    This works by querying Stormpath with the user's credentials, and
    either getting back the User object itself, or an exception (in
    which case well tell the user their credentials are invalid).

    If the user is valid, we'll log them in and store their session.
    """
    if request.method == 'GET':
        return render_template('login.html')
    try:
        user = stormpath.User.from_login(
            request.form.get('email'),
            request.form.get('password'),
        )
    except StormpathError as err:
        return render_template('login.html', error=err.message)
    stormpath.login_user(user, remember=True)
    return redirect(request.args.get('next') or url_for('dashboard'))
Esempio n. 12
0
def login():
  error = None

  # Attempt to login using email and password
  if request.method == 'POST':
    try:
      _user = User.from_login(
        request.form['email'],
        request.form['password'],
        )

      # No errors occur and user is logged in
      login_user(_user, remember = True)
      flash('You were logged in.')

      return redirect(url_for('show_posts'))

    except (StormpathError, err):
      error = err.message

  return render_template('login.html', error = error)
Esempio n. 13
0
def register():
    """Allows a user to register for the site.

    This will create a new User, and then log the user into their new
    account immediately (no email verification required).
    """
    if request.method == 'GET':
        return render_template('register.html')
    try:
        # Create a new Stormpath User.
        user = stormpath_manager.application.accounts.create({
            'email': request.form.get('email'),
            'password': request.form.get('password'),
            'given_name': request.form.get('given_name'),
            'surname': request.form.get('surname'),
        })
        user.__class__ = stormpath.User
    except StormpathError as err:
        # If something fails, we'll display a user-friendly error message.
        return render_template('register.html', error=err.message)
    stormpath.login_user(user, remember=True)
    return redirect(url_for('dashboard'))
Esempio n. 14
0
def register():
    error = None
    form = RegisterForm()
    if form.validate_on_submit():
        try:
            account = stormpath_manager.application.accounts.create({
                'given_name':
                form.given_name.data,
                'surname':
                form.surname.data,
                'username':
                form.username.data,
                'email':
                form.email.data,
                'password':
                form.password.data,
                'custom_data': {
                    'tutno':
                    1,
                    'completed':
                    False,
                    'avatar':
                    'http://www.gravatar.com/avatar/%s?d=mm&s=%d' %
                    (md5(form.email.data.encode('utf-8')).hexdigest(), 128)
                }
            })
            _user = User.from_login(
                form.email.data,
                form.password.data,
            )
            login_user(_user, remember=True)
            flash('You were logged in.')
            tutnames = db.session.query(Tut.name).all()
            tutnames = [tutname for (tutname, ) in tutnames]
            return render_template('startpage.html', tutnames=tutnames)
        except StormpathError, err:
            error = err.message
            flash('Please try again' + str(error))
Esempio n. 15
0
        return render_template('register.html')

    try:
        # Create a new Stormpath User.
        _user = stormpath_manager.application.accounts.create({
            'email': request.form.get('email'),
            'password': request.form.get('password'),
            'given_name': 'John',
            'surname': 'Doe',
        })
        _user.__class__ = User
    except StormpathError, err:
        # If something fails, we'll display a user-friendly error message.
        return render_template('register.html', error=err.message)

    login_user(_user, remember=True)
    return redirect(url_for('dashboard'))


@app.route('/login', methods=['GET', 'POST'])
def login():
    """
    This view logs in a user given an email address and password.

    This works by querying Stormpath with the user's credentials, and either
    getting back the User object itself, or an exception (in which case well
    tell the user their credentials are invalid).

    If the user is valid, we'll log them in, and store their session for later.
    """
    if request.method == 'GET':
Esempio n. 16
0
        _user = stormpath_manager.application.accounts.create({
            'email':
            request.form.get('email'),
            'password':
            request.form.get('password'),
            'given_name':
            'John',
            'surname':
            'Doe',
        })
        _user.__class__ = User
    except StormpathError, err:
        # If something fails, we'll display a user-friendly error message.
        return render_template('register.html', error=err.message)

    login_user(_user, remember=True)
    return redirect(url_for('dashboard'))


@app.route('/login', methods=['GET', 'POST'])
def login():
    """
    This view logs in a user given an email address and password.

    This works by querying Stormpath with the user's credentials, and either
    getting back the User object itself, or an exception (in which case well
    tell the user their credentials are invalid).

    If the user is valid, we'll log them in, and store their session for later.
    """
    if request.method == 'GET':