Exemple #1
0
def _login(username, password):
    user = User.get_from_credentials(username, password)
    if not user:
        record_user_event(username, 'login failed', commit=True)
        abort(400, error='invalid_grant')
    record_user_event(username, 'login succeeded', user=user)
    return user
Exemple #2
0
def _register_user(form):
    user = User.create_with_channel(
        username=form.username.data,
        first_name=form.first_name.data,
        last_name=form.last_name.data,
        date_of_birth=form.date_of_birth.data,
        email=form.email.data.lower(),
        password=form.password.data,
        gender=form.gender.data or None,
        locale=form.locale.data)
    record_user_event(user.username, 'registration succeeded', user=user)

    # Check if anyone has emailed this person before
    senders = models.ExternalFriend.query.filter(
        models.ExternalFriend.external_system == 'email',
        models.ExternalFriend.email == user.email
    ).join(
        User,
        User.id == models.ExternalFriend.user
    ).with_entities(User)

    if senders.count():
        db.session.flush()  # Get the user id before the commit
        from rockpack.mainsite.services.share import api
        for sender in senders:
            api.create_reverse_email_friend_association(sender, user)

    return user
Exemple #3
0
 def _valid(form, field):
     if not field.data:
         return
     if field.data != User.sanitise_username(field.data):
         raise wtf.ValidationError(_('Username can only contain alphanumerics.'))
     exists = username_exists(field.data)
     if exists == 'reserved':
         raise wtf.ValidationError(_('"%s" is reserved.') % field.data)
     elif exists:
         raise wtf.ValidationError(_('"%s" already taken.') % field.data)
     naughty_word_validator(form, field)
Exemple #4
0
 def create_test_user(self, **kwargs):
     postfix = uuid.uuid4().hex
     userdata = dict(
         username='******' + postfix,
         password='******',
         first_name='Alexia',
         last_name='Barrichello',
         date_of_birth=date(2000, 1, 1),
         email='noreply+test_' + postfix + '@rockpack.com',
         avatar='',
         refresh_token='',
         is_active=True,
         locale='en-us',
     )
     userdata.update(kwargs)
     with self.app.test_request_context():
         user = User.create_with_channel(**userdata)
         self.session.commit()
     return user
Exemple #5
0
def _external_login(external_user, locale):
    user = models.ExternalToken.user_from_uid(external_user.system, external_user.id)

    if user and not user.is_active:
        record_user_event(user.username, 'login failed', user=user, commit=True)
        abort(400, error='invalid_grant')

    if user:
        record_user_event(user.username, 'login succeeded', user=user)
        registered = False
    else:
        # New user
        user = User.create_from_external_system(external_user, locale)
        record_user_event(user.username, 'registration succeeded', user=user)
        registered = True

    # Update the token record if needed
    models.ExternalToken.update_token(user, external_user)

    return user, registered
Exemple #6
0
 def reset_password(self):
     user = User.get_from_credentials(request.form['username'], None)
     if not user:
         abort(400)
     record_user_event(user.username, 'password reset requested', user=user, commit=True)
     send_password_reset(user.id)