Example #1
0
def registration():
    form = RegistrationForm()

    if form.validate_on_submit():
        db_sess = db_session.create_session()
        if db_sess.query(User).filter(User.email == form.email.data).first():
            return render_template(
                'registration.html',
                title='Регистрация',
                form=form,
                message='Пользователь с такой почтой уже зарегистрирован')
        user = User(surname=form.surname.data,
                    name=form.name.data,
                    age=form.age.data,
                    position=form.position.data,
                    speciality=form.speciality.data,
                    address=form.address.data,
                    email=form.email.data,
                    city_from=form.city.data)
        user.set_password(form.password.data)

        db_sess.add(user)
        db_sess.commit()

        login_user(user)
        return redirect('/')

    return render_template('registration.html', title='Регистрация', form=form)
Example #2
0
    def run(self):
        res = sign_up_user(self.username, self.password, self.email)
        if not res[0]:
            return error("Unable to add User: {}".format(res[1]))

        new_user = User()
        # new_user.user_id = self.username
        new_user.username = self.username
        new_user.email = self.email
        new_user.first_name = self.post_body.get('first_name')
        new_user.last_name = self.post_body.get('last_name')
        new_user.phone_number = self.post_body.get('phone_number')
        new_user.organization = self.post_body.get('organization')
        print new_user.organization

        try:
            new_user.save()
        except Exception as e:
            ok = admin_delete_user(self.username)
            if not ok:
                return error("Unable to delete User from user pool")
            return error("Error creating new User: {}".format(e))

        debug("SIGNUP_USER", "SUCCESS!")
        return success(
            'User signed up, check your email for confirmation code!')
Example #3
0
    def run(self):
        # may be an opportunity to FURTHER abstract out this run step.
        # even if just for AddUser().
        # add to user pool:
        ok = sign_up_user(self.username, self.password, self.email)
        if not ok:
            return error("Unable to add User")

        # TODO: Implement confirm endpoint/ui flow, then delete
        ok = admin_confirm_signup(self.username)
        if not ok:
            d = admin_delete_user(self.username)
            if not d:
                return error("Unable to delete User from user pool")
            return error("Unable to confirm User")

        new_user = User()
        new_user.username = self.username
        new_user.email = self.email
        new_user.first_name = self.post_body.get('first_name')
        new_user.last_name = self.post_body.get('last_name')
        new_user.phone_number = self.post_body.get('phone_number')
        new_user.organization = self.post_body.get('organization')
        print new_user.organization

        try:
            new_user.save()
        except Exception as e:
            ok = admin_delete_user(self.username)
            if not ok:
                return error("Unable to delete User from user pool")
            return error("Error creating new User: {}".format(e))

        debug("ADD_USER", "SUCCESS!")
        return success('User created!')
def __import_users():
    session = session_factory.create_session()
    if session.query(User).count() > 0:
        return

    data_service.get_default_user()

    user2 = User()
    user2.email = "*****@*****.**"
    user2.name = "user 2"
    session.add(user2)
    session.commit()
def __import_users():
    session = session_factory.create_session()
    if session.query(User).count() > 0:
        return

    data_service.get_default_user()

    user2 = User()
    user2.email = '*****@*****.**'
    user2.name = 'Natalia'
    session.add(user2)
    session.commit()
Example #6
0
def get_default_user():
    session = session_factory.create_session()

    user = session.query(User).filter(User.email == "*****@*****.**").first()
    if user:
        return user

    user = User()
    user.name = "Test user 1"
    user.email = "*****@*****.**"
    session.add(user)

    session.commit()

    return user
Example #7
0
def get_default_user():
    session = session_factory.create_session()

    user = session.query(User).filter(User.email == '*****@*****.**').first()
    if user:
        return user

    user = User()
    user.email = '*****@*****.**'
    user.name = 'Ruslan'
    session.add(user)

    session.commit()

    return user
Example #8
0
def get_default_user():
    session = session_factory.create_session()

    user = session.query(User).filter(User.email == '*****@*****.**').first()
    if user:
        return user

    user = User()
    user.email = '*****@*****.**'
    user.name = 'test user 1'
    session.add(user)

    session.commit()

    return user
Example #9
0
def update_user(event, context):
    debug('UPDATE_USER', 'event is: {}'.format(event))

    post_body = get_event_value(event, key='body')

    if not post_body:
        return error('missing/bad post body')
    debug('UPDATE_USER', 'post body is: {}'.format(post_body))

    params = get_event_value(event, 'pathParameters')
    debug('UPDATE_USER', 'params is: {}'.format(params))
    if not params:
        return error("Invalid parameters")

    username = params.get('username')

    try:
        user = User.query(username, limit=1).next()
        debug('UPDATE_USER', 'user is: {}'.format(user))

        attributes = {}
        for key, value in post_body.items():
            setattr(user, key, value)

        user.save()
    except StopIteration:
        return not_found()
    except Exception as e:
        return error(e)

    return success(user.to_dict())
Example #10
0
 def run(self):
     all_users = []
     try:
         users = User.scan()
         for user in users:
             all_users.append(user.to_dict())
     except Exception as e:
         return error("Error listing all users {}".format(e))
     return success(all_users)
    def post(self):
        args = parser.parse_args()
        session = db_session.create_session()
        user = User()

        user.id = args['id']
        user.name = args['name']
        user.email = args['email']
        user.role = args['role']
        user.avatar_path = args['avatar_path']
        user.set_password(args['password'])

        session.add(user)
        session.commit()
        return jsonify({'message': 'SUCCESS'})
Example #12
0
    def run(self):
        try:
            user = User.query(self.username, limit=1).next()
        except StopIteration:
            return not_found()
        except Exception as e:
            return error(e)

            debug("GET_USER", "SUCCESS!")
        return success(user.to_dict())
Example #13
0
    def run(self):
        debug('test', self.username + ' ' + self.confirm_code)
        res = validate_user_on_aws(self.username, self.confirm_code)
        if not res[0]:
            try:
                user = User.query(self.username, limit=1).next()
                user.delete()
                ok = admin_delete_user(self.username)
                if not ok:
                    return error("Unable to delete User from user pool")
                return error("Unable to validate User: {}".format(res[1]))
            except StopIteration:
                return not_found("User not found in dynamodb")
            except Exception as e:
                return error(e)

        debug("VALIDATE_USER", "SUCCESS!")
        user_id = User.get_user_by_username(self.username).user_id
        resp = dict(validated=True, username=self.username, user_id=user_id)
        return success(resp)
Example #14
0
    def run(self):
        user_list = []
        for user in self.users:
            try:
                user = User.query(user, limit=1).next()
                user_list.append(user.user_id)
            except StopIteration:
                return not_found()
            except Exception as e:
                return error(e)

        debug("GET_USER_lIST", "SUCCESS!")
        return success(user_list)
Example #15
0
    def run(self):

        user = User.get_user_by_userid(self.user_id)

        if not user:
            return not_found('user_id {} not found'.format(self.user_id))

        identity_token, access_token = refresh_tokens(self.refresh_token)

        if identity_token and access_token:
            response = dict(identity_token=identity_token,
                            access_token=access_token)
            return success(response)
        else:
            return error("Error refreshing tokens")
Example #16
0
 def register(self, ui):
     login = ui['login'].text()
     password = ui['password'].text()
     repeat_password = ui['repeat'].text()
     if password != repeat_password:
         ui['info'].setText('Пароли должны совпадать!')
     elif not login or not password:
         ui['info'].setText('Неверный логин или пароль!')
     else:
         session = db_session.create_session()
         user = User(login=login,
                     password_hash=generate_password_hash(password))
         session.add(user)
         session.commit()
         self.parent().current_user = user
         self.setParent(None)
Example #17
0
def forgot_password(event, context):
    debug('FORGOT_PASSWORD', 'event is: {}'.format(event))
    post_body = get_event_value(event, 'pathParameters')
    params = get_event_value(event, 'pathParameters')
    if not params:
        return error("Invalid path")

    username = params.get('username')

    try:
        user = User.query(username, limit=1).next()
    except StopIteration:
        return not_found()
    except Exception as e:
        return error(e)

    # call forgot_password
    ok = admin_forgot_password(username)
    if not ok:
        return error("Unable to retrieve data from user pool")

    return success('User has been sent a verification code')