Пример #1
0
    def put(self):
        """
        Create a new requester.

        :param str email: requester email address
        :param str password: requester password

        :returns: JSON with requester_id string to use in future requests.

        **Example response:**

        .. code-block:: json

            {
                "requester_id": "12345"
            }

        """
        #TODO password security???
        args = requester_parser.parse_args()
        email = args['email']
        password = args['password']
        register_user(email=email, password=password)
        # TODO best way to return requester's ID?
        requesterDocument = Requester.objects.get_or_404(email=email)
        if requesterDocument:
            return {'requester_id': str(requesterDocument.id)}
        else:
            return requesterDocument
Пример #2
0
    def post(self):
        data = self.clean(g.request_json)

        if not User.is_unique(data['email']):
            raise t.DataError({'email': _("This email is already taken")})

        register_user(email=data['email'], password=data.get('password', '*'))
        return self._get_response()
Пример #3
0
    def post(self):
        data = self.clean(g.request_json)

        if not User.is_unique(data['email']):
            raise t.DataError({'email': _("This email is already taken")})

        register_user(email=data['email'], password=data.get('password', '*'))
        return self._get_response()
Пример #4
0
def register_local():
    form = EeaLocalRegisterForm(flask.request.form)

    if form.validate_on_submit():
        register_user(**form.to_dict())
        return flask.render_template('message.html', message="")

    return flask.render_template('auth/register_local.html', **{
        'register_user_form': form,
    })
Пример #5
0
def register_local():
    form = Art17LocalRegisterForm(request.form)

    if form.validate_on_submit():
        register_user(**form.to_dict())
        return render_template('message.html', message="")

    return render_template('auth/register_local.html', **{
        'register_user_form': form,
    })
Пример #6
0
    def post(self):
        data = request.json or abort(http.BAD_REQUEST)
        try:
            data = self.validation.check(data)

            if not User.is_unique(data["email"]):
                raise t.DataError({"email": _("This email is already taken")})

            register_user(email=data["email"], password=data.get("password", ""))

            response, status = self._get_response(), http.CREATED

        except t.DataError as e:
            response, status = e.as_dict(), http.BAD_REQUEST
        return jsonify_status_code(response, status)
Пример #7
0
def add_test_users():
    try:
        test_user = schema.requester.Requester.objects.get(
            email='*****@*****.**')
    except:
        test_user = register_user(email='*****@*****.**',
                                  password='******')
Пример #8
0
def register_post():

    if current_user.is_authenticated():
        return redirect(url_for('front_page'))

    form = RegistrationForm(request.form)
    if form.validate():
        user_dict = {
            "email": form.email.data,
            "password":  form.password.data

        }
        u = register_user(**user_dict)

        u.created_at=datetime.datetime.utcnow()
        u.modified_at=datetime.datetime.utcnow()

        u.first_name=form.first_name.data
        u.last_name=form.last_name.data
        u.ran_through_first_run_wizard=False
        custom_questions = dict()
        for c in form.custom_fields():
            custom_questions[c.id] = c.data

        u.custom_questions_json = custom_questions
        db.session.add(u)
        db.session.commit()
        g.user = u
        login_user(u, force=True)
        flash('You were successfully logged in')

        return redirect(url_for('front_page'))

    else:
        return render('register.html', form=form)
Пример #9
0
def register():
    """View function which handles a registration request."""

    if request.json:
        form_data = MultiDict(request.json)
    else:
        form_data = request.form

    form = forms.RegisterForm(form_data)

    if form.validate_on_submit():
        # 'register_user' expects a 'password' argument to be provided; it's
        #   simpler to just provide an empty password than reimplement the
        #   entire rest of the function locally
        user = register_user(password=None, **form.to_dict())
        if user.password is not None:
            # if the password encryption is not plaintext, the password of
            #   'None' will have been encrypted to some string
            user.password = None
            user.save()
        form.user = user

        if not request.json:
            return redirect(get_post_register_redirect())
        return _render_json(form, include_auth_token=True)

    if request.json:
        return _render_json(form)

    return render_template(config_value('REGISTER_USER_TEMPLATE'),
                           register_user_form=form,
                           **_ctx('register'))
Пример #10
0
    def run(self):
        deployments = Deployment.objects
        option = prompt_choices('Deployment', [
            (str(i), v) for i, v in enumerate(deployments, 1)])
        deployment = deployments[int(option) - 1]
        email = prompt('Email')
        password = prompt_pass('Password')
        password_confirm = prompt_pass('Confirm Password')

        can_create, form_errors = can_create_user(email, password,
                                                  password_confirm, deployment)

        if can_create:
            try:
                user = register_user(email=email, password=password)
            except socket.error as e:
                # if there's an error sending the notification email,
                # recover
                print 'Error sending confirmation email: {}'.format(e)
                user = users.get(email=email, deployment=None)
            user.update(set__deployment=deployment)
            print '\nUser created successfully'
            print 'User(id=%s email=%s)' % (user.id, user.email)
            return
        print '\nError creating user:'******'\n'.join(errors)
Пример #11
0
    def post(self):
        form = RegisterForm()
        if form.validate_on_submit():
            user = register_user(**form.to_dict())
            form.user = user

        return _make_response(form, include_auth_token=True)
Пример #12
0
    def run(self):
        """Run the command."""
        # Get the information.
        email = prompt('Email')
        name = prompt('Name')
        password = prompt_pass('Password')
        password_confirm = prompt_pass('Confirm Password')
        data = MultiDict({
            'email': email,
            'password': password,
            'password_confirm': password_confirm,
        })

        # Validate the form.
        form = RegisterForm(data, csrf_enabled=False)
        if form.validate():
            user = register_user(name=name, email=email, password=password)
            print('\nUser created successfully.')
            print('User(id={} email={})'.format(user.id, user.email))
            return

        # If something went wrong, report it and exit out.
        print('\nError creating user:'******'\n'.join(errors))
        sys.exit(1)
Пример #13
0
    def post(self):
        form = RegisterForm()
        if form.validate_on_submit():
            user = register_user(**form.to_dict())
            form.user = user

        return _make_response(form, include_auth_token=True)
Пример #14
0
def new_application():
    """Begin a new application."""

    if current_user.is_authenticated():
        existing = models.Application.objects(
            submitter=current_user.id).first()
        if existing:
            return redirect(
                url_for('application', application_id=existing.id, step=1))
        else:
            new_app = models.Application(submitter=current_user.id)
            new_app.save()
            utils.send_application_creation_email(new_app)
            return redirect(
                url_for('application', application_id=new_app.id, step=1))

    form = forms.ApplicationFormStep_New()
    if form.validate_on_submit():
        if user_datastore.get_user(form.email.data):
            flash(
                'A user with that email address already exists. Perhaps you meant to log in instead?',
                'error')
            return redirect(url_for('new_application'))
        else:
            registerable.register_user(name=form.name.data,
                                       email=form.email.data,
                                       password=form.password.data,
                                       roles=['student'])

            user = user_datastore.get_user(form.email.data)
            application = models.Application(submitter=user.id)
            application.save()
            utils.send_application_creation_email(application)

            auth.login(user)
            flash((
                'A new account has been created with the email address <b>' +
                user.email +
                '</b>. You don\'t need to complete your application '
                'in one sitting; return later and log back in to continue right where you left off.'
            ), 'success')
            return redirect(
                url_for('application', application_id=application.id, step=2))

    return render_template('application_new.html', form=form)
Пример #15
0
def add_user():
    form = forms.UserRegistrationForm()
    if form.validate_on_submit():
        user = registerable.register_user(email=form.email.data, fullname=form.fullname.data,
                                          password=form.password.data)
        flash("User {} was created".format(form.email.data))
        return redirect(url_for('.users'))

    return render_template('admin/user_add.html', form=form)
Пример #16
0
def register():
    form_class = _security.register_form
    form_data = MultiDict(request.json)
    form = form_class(form_data, csrf_enabled=False)
    if form.validate_on_submit():
        user = register_user(**form.to_dict())
        form.user = user
        message = 'User: %s created successfully!' % user.email
        return jsonify(dict(user=user.to_json(), message=message)), 200
    return jsonify(dict(errors=form.errors)), 400
Пример #17
0
def register():
    form_class = _security.register_form
    form_data = MultiDict(request.json)
    form = form_class(form_data, csrf_enabled=False)
    if form.validate_on_submit():
        user = register_user(**form.to_dict())
        form.user = user
        message = 'User: %s created successfully!' % user.email
        return jsonify(dict(user=user.to_json(), message=message)), 200
    return jsonify(dict(errors=form.errors)), 400
Пример #18
0
def create_superuser(email, password):
    admin = user_datastore.find_or_create_role('admin')

    user = User.query.filter_by(email=email).first()
    if not user:
        user = register_user(email=email, password=password)
        user.confirmed_at = datetime.now()
        db.session.add(user)
        db.session.commit()

    user_datastore.add_role_to_user(user, admin)
    db.session.commit()
Пример #19
0
 def run(self):
     email = prompt('Email')
     password = prompt_pass('Password')
     password_confirm = prompt_pass('Confirm Password')
     data = MultiDict(dict(email=email, password=password, password_confirm=password_confirm))
     form = RegisterForm(data, csrf_enabled=False)
     if form.validate():
         user = register_user(email=email, password=password)
         print '\nUser created successfully'
         print 'User(id=%s email=%s' % (user.id, user.email)
         return
     print '\nError creating user:'******'\n'.join(errors)
Пример #20
0
def new_application():
    """Begin a new application."""

    if current_user.is_authenticated():
        existing = models.Application.objects(submitter=current_user.id).first()
        if existing:
            return redirect(url_for('application', application_id=existing.id, step=1))
        else:
            new_app = models.Application(submitter=current_user.id)
            new_app.save()
            utils.send_application_creation_email(new_app)
            return redirect(url_for('application', application_id=new_app.id, step=1))

    form = forms.ApplicationFormStep_New()
    if form.validate_on_submit():
        if user_datastore.get_user(form.email.data):
            flash('A user with that email address already exists. Perhaps you meant to log in instead?', 'error')
            return redirect(url_for('new_application'))
        else:
            registerable.register_user(
                name=form.name.data,
                email=form.email.data,
                password=form.password.data,
                roles=['student']
            )

            user = user_datastore.get_user(form.email.data)
            application = models.Application(submitter=user.id)
            application.save()
            utils.send_application_creation_email(application)

            auth.login(user)
            flash(('A new account has been created with the email address <b>' + user.email + '</b>. You don\'t need to complete your application '
                'in one sitting; return later and log back in to continue right where you left off.'), 'success')
            return redirect(url_for('application', application_id=application.id, step=2))

    return render_template('application_new.html', form=form)
Пример #21
0
 def run(self):
     email = prompt('Email')
     password = prompt_pass('Password')
     password_confirm = prompt_pass('Confirm Password')
     data = MultiDict(
         dict(email=email,
              password=password,
              password_confirm=password_confirm))
     form = RegisterForm(data, csrf_enabled=False)
     if form.validate():
         user = register_user(email=email, password=password)
         print '\nUser created successfully'
         print 'User(id=%s email=%s' % (user.id, user.email)
         return
     print '\nError creating user:'******'\n'.join(errors)
Пример #22
0
    def run(self):
        if models.Deployment.objects.count() > 0:
            print 'You already have deployments set up.'
            return

        name = prompt('Name of new deployment')
        hostname = prompt('Hostname for deployment')

        deployment = models.Deployment.objects.create(name=name,
                                                      hostnames=[hostname])

        # create the roles
        role_names = ['manager', 'clerk', 'analyst', 'admin']
        for role_name in role_names:
            role = models.Role.objects.create(name=role_name)

        # create the admin user
        email = prompt('Email for admin user')
        password = prompt_pass('Password for admin user')
        password_confirm = prompt_pass('Confirm password')

        data = MultiDict({
            'email': email,
            'password': password,
            'password_confirm': password_confirm
        })
        form = RegisterForm(data, csrf_enabled=False)
        if form.validate():
            try:
                user = register_user(email=email, password=password)
            except socket.error as e:
                print 'Error sending registration email: {}'.format(e)
                user = services.users.get(email=email, deployment=None)
            user.update(set__deployment=deployment, add_to_set__roles=role)

            print '\nUser created successfully'
            print 'User(id=%s email=%s)' % (user.id, user.email)
        else:
            print '\nError creating user:'******'\n'.join(errors)

        # create at least one event
        from apollo.manage.deployments import CreateEventCommand
        CreateEventCommand._create_event(deployment)
Пример #23
0
def register_facebook_account_post():
    if current_user.is_authenticated():
        return redirect(url_for('front_page'))

    registration_form = RegistrationForm(request.form)
    registration_form.validate()
    pw = registration_form.password.data

    user_dict = {
        "email": registration_form.email.data,
        "password":  registration_form.password.data

    }
    u = register_user(**user_dict)

    u.created_at=datetime.datetime.utcnow()
    u.modified_at=datetime.datetime.utcnow()

    u.first_name=registration_form.first_name.data
    u.last_name=registration_form.last_name.data
    u.ran_through_first_run_wizard=False
    custom_questions = dict()
    for c in registration_form.custom_fields():
        custom_questions[c.id] = c.data

    u.custom_questions_json = custom_questions
    auth = FacebookUser.query.filter_by(id=session['fb_auth']).first()

    u.profile_image = 'https://graph.facebook.com/%s/picture' % auth.facebook_id

    auth.user = u
    db.session.add(u)
    db.session.add(auth)
    db.session.commit()
    if auth.user is not None:
        g.user = auth.user
        login_user(auth.user, force=True)
        flash('You were successfully logged in')

    return redirect(url_for('front_page'))
Пример #24
0
def register(provider_id=None):
    if current_user.is_authenticated():
        return redirect(request.referrer or '/')

    form = RegisterForm()

    if provider_id:
        provider = get_provider_or_404(provider_id)
        connection_values = session.get('failed_login_connection', None)
    else:
        provider = None
        connection_values = None

    if form.validate_on_submit():
        #ds = current_app.security.datastore
        user = register_user(**form.to_dict())


        # See if there was an attempted social login prior to registering
        # and if so use the provider connect_handler to save a connection
        #connection_values = session.pop('failed_login_connection', None)

        if connection_values:
            connection_values['user_id'] = user.id
            connect_handler(connection_values, provider)

        if login_user(user):
            #ds.commit()
            flash('Account created successfully', 'info')
            return redirect(url_for('.index'))

        return render_template('thanks.html', user=user)

    login_failed = int(request.args.get('login_failed', 0))

    return render_template('security/register_user.html',
                           register_user_form=form,
                           provider=provider,
                           login_failed=login_failed,
                           connection_values=connection_values)
Пример #25
0
def register():
    form_data = MultiDict(request.json)
    form = RegisterForm(form_data)
    user = register_user(**form.to_dict())
    login_user(user)
    return current_user.get_auth_token()
Пример #26
0
    def run(self):
        if models.Deployment.objects.count() > 0:
            print 'You already have deployments set up.'
            return

        name = prompt('Name of new deployment')
        hostname = prompt('Hostname for deployment')

        deployment = models.Deployment.objects.create(
            name=name,
            hostnames=[hostname]
        )

        # create the roles
        role_names = ['manager', 'clerk', 'analyst', 'admin']
        for role_name in role_names:
            role = models.Role.objects.create(name=role_name)

        # create the admin user
        email = prompt('Email for admin user')
        password = prompt_pass('Password for admin user')
        password_confirm = prompt_pass('Confirm password')

        data = MultiDict({
            'email': email,
            'password': password,
            'password_confirm': password_confirm
        })
        form = RegisterForm(data, csrf_enabled=False)
        if form.validate():
            try:
                user = register_user(email=email, password=password)
            except socket.error as e:
                print 'Error sending registration email: {}'.format(e)
                user = services.users.get(email=email, deployment=None)
            user.update(set__deployment=deployment, add_to_set__roles=role)

            print '\nUser created successfully'
            print 'User(id=%s email=%s)' % (user.id, user.email)
            return
        print '\nError creating user:'******'\n'.join(errors)

        # create at least one event
        name = prompt('Event name')
        start = end = None
        while True:
            try:
                start = datetime.strptime(
                    prompt('Start date (YYYY-MM-DD)'), '%Y-%m-%d')
            except ValueError:
                pass
            if start:
                break
        while True:
            try:
                end = datetime.strptime(
                    prompt('End date (YYYY-MM-DD)'), '%Y-%m-%d')
            except ValueError:
                pass
            if end:
                break

        event, _ = models.Event.objects.get_or_create(
            name=name,
            deployment=deployment)
        event.start_date = datetime.combine(start, datetime.min.time())
        event.end_date = datetime.combine(end, datetime.max.time())
        event.save()
Пример #27
0
    def run(self):
        if models.Deployment.objects.count() > 0:
            print 'You already have deployments set up.'
            return

        name = prompt('Name of new deployment')
        hostname = prompt('Hostname for deployment')

        deployment = models.Deployment.objects.create(name=name,
                                                      hostnames=[hostname])

        # create the roles
        role_names = ['manager', 'clerk', 'analyst', 'admin']
        for role_name in role_names:
            role = models.Role.objects.create(name=role_name)

        # create the admin user
        email = prompt('Email for admin user')
        password = prompt_pass('Password for admin user')
        password_confirm = prompt_pass('Confirm password')

        data = MultiDict({
            'email': email,
            'password': password,
            'password_confirm': password_confirm
        })
        form = RegisterForm(data, csrf_enabled=False)
        if form.validate():
            try:
                user = register_user(email=email, password=password)
            except socket.error as e:
                print 'Error sending registration email: {}'.format(e)
                user = services.users.get(email=email, deployment=None)
            user.update(set__deployment=deployment, add_to_set__roles=role)

            print '\nUser created successfully'
            print 'User(id=%s email=%s)' % (user.id, user.email)
            return
        print '\nError creating user:'******'\n'.join(errors)

        # create at least one event
        name = prompt('Event name')
        start = end = None
        while True:
            try:
                start = datetime.strptime(prompt('Start date (YYYY-MM-DD)'),
                                          '%Y-%m-%d')
            except ValueError:
                pass
            if start:
                break
        while True:
            try:
                end = datetime.strptime(prompt('End date (YYYY-MM-DD)'),
                                        '%Y-%m-%d')
            except ValueError:
                pass
            if end:
                break

        event, _ = models.Event.objects.get_or_create(name=name,
                                                      deployment=deployment)
        event.start_date = datetime.combine(start, datetime.min.time())
        event.end_date = datetime.combine(end, datetime.max.time())
        event.save()