Exemplo n.º 1
0
def _create(request):
  form = NewUserForm(request.POST)
  if form.is_valid():
    new_user = form.save()
    messages.success(request, "New user created!")
    return redirect(new_user)
  return new(request, form)
Exemplo n.º 2
0
    def post(self):        
        if request.method == 'POST':
            form = NewUserForm()
            if form.validate_on_submit():
                try:
                    user = User.create()
                    # Set Permissions
                    if current_user.is_admin():
                        user.role = int(form.role.data)

                    del form.role
                    del form.timezone
                    del form.lang
                    form.populate_obj(user)
                    user.set_password(form.password.data)
                    user.save()

                    flash(gettext('User was succesfully saved'))
                    return redirect(url_for('UsersView:get',id=user.id))                     
                except:
                    flash(gettext('Error while creating the user'), 'error')
                    raise                    
            else:
                flash(gettext('Invalid submission, please check the messages below'), 'error')
        else:
            form = NewUserForm()

        return render_template('admin/users/add.html', 
            title = gettext('Create new user'),
            form = form,
            user = [])
Exemplo n.º 3
0
def admin_users():

    from forms import NewUserForm

    if not current_user.is_admin:
        abort(403)

    new_user_form = NewUserForm()

    if new_user_form.validate_on_submit():
        account = aac.library.find_or_new_account(new_user_form.username.data)
        account.major_type = 'user'
        account.minor_type = new_user_form.account_type.data
        if account.minor_type == 'api':
            account.encrypt_secret(new_user_form.password.data)
        else:
            account.encrypt_password(new_user_form.password.data)
        aac.library.commit()
        flash("Created new user: {}".format(new_user_form.username.data), "success")

    if request.method == 'POST' and request.form.get('delete'):
        aac.library.delete_account(request.form['delete'])
        aac.library.commit()

    else:
        for k,v in new_user_form.errors.items():
            flash("{}: {}".format(k, v), "error")

    cxt = dict(
        users=[a for a in aac.library.accounts.values() if a['major_type'] == 'user'],
        new_user_form=NewUserForm(),
        **aac.cc
    )

    return aac.render('admin/users.html', **cxt)
Exemplo n.º 4
0
def signup():
    """signup route"""
    new_user_form = NewUserForm()

    if new_user_form.validate_on_submit():
        existing_user = User.query.filter_by(
            username=new_user_form.username.data).first()
        # checks that username has not been taken
        if existing_user is None:
            # create user
            user = User.signup(
                username=new_user_form.username.data,
                email=new_user_form.email.data,
                password=new_user_form.password.data,
                country=new_user_form.country.data,
                state=new_user_form.state.data
            )

            db.session.commit()
            login_user(user)

            flash('User Created', 'success')

            return redirect(url_for('portfolio'))

    flash('Username is already taken', 'warning')
    return redirect(url_for('homepage'))
Exemplo n.º 5
0
def new(request, usp=None):
    data = {}
    if usp:
        data['usp'] = True
    if "next" in request.POST:
        data['next'] = clear_url(request, request.POST['next'])

    if "create" in request.POST:        
        form = NewUserForm(request.POST)
        if form.is_valid():
            user = form.save()
            
            try:
                send_mail(_(u"Criação de conta no Delos"), user, "users/email_newuser.html", {'name': user.name})
            except:
                pass # mail couldn't be sent, probably email is wrong... what should I do oh Lord?
            
            password = request.POST['password1']
            next = clear_url(request, request.POST.get('next', '') )
            request.POST = QueryDict('username=%s&password=%s'% (user.identification, password) )

            return login(request, next)
    else:
        form = NewUserForm()
    data['form'] = form
    return render_to_response('users/create.html', data, context_instance=RequestContext(request))
Exemplo n.º 6
0
def user_signup():
    if current_user.get_id() != None:
        flash('You are already logged in!', 'danger')
        return redirect(f'/my-lists/{current_user.id}')
    form = NewUserForm()
    if form.validate_on_submit():
        if pf.is_profane(form.username.data) == True:
            flash('Please avoid using profanity!', 'danger')
        else:
            try:
                user = User.signup(
                    username=form.username.data,
                    password=form.password.data,
                    email=form.email.data,
                    avatar_url=form.avatar_url.data
                    or User.avatar_url.default.arg,
                )
                db.session.commit()
                login_user(user)
                send_email(
                    'Welcome to Aniroku', user.email,
                    'Create new lists and share with your friends, enjoy!')
                return redirect(f"/my-lists/{user.id}")
            except IntegrityError:
                db.session.rollback()
                invalid_signup(form.username.data, form.email.data)
    return render_template('signup.html', form=form)
Exemplo n.º 7
0
 def post(self, email, password, first_name, last_name):
     new_user_form = NewUserForm(email, password, first_name, last_name)
     if new_user_form.validate_on_submit():
         new_user = User(email, password, first_name, last_name)
         db_session.add(new_user)
         db_session.commit()
         return {'success': 'added user with id - {}'.format(new_user.id)}
     else:
         return {"fail": "wrong format"}
Exemplo n.º 8
0
def add_user():
		form=NewUserForm () #creating a new user
		if form.validate_on_submit(): #if all the areas in the form that NEED to be complete are go ahead and submit form 
			user=User() #setting up the database to receive the user
			form.populate_obj(user) #inserting the user info into the data
			db.session.add(user) #add
			db.session.commit() #commit
			return redirect('/') #go back to the page
		return render_template('add_user.html', form = form)
Exemplo n.º 9
0
def create_user():
	form = NewUserForm()
	if form.validate_on_submit():
	  user = User(form.username.data, form.password.data)
	  db.session.add(user)
	  db.session.commit()
	  flash('You Created A User!')
	  return redirect(url_for('index_user'))
	return render_template('new.html', form=form)
Exemplo n.º 10
0
def newuser():
    form = NewUserForm(request.form)
    if request.method == 'POST' and form.validate():
        user = User(form.boxuseremail.data, form.mitrend_user.data, "False", form.password.data)
        db.session.add(user)
        db.session.commit()
        app_boxsession.initUser(form.boxuseremail.data)
        return redirect(url_for('registered'))
    return render_template('newuser.html', title = 'New User Information', form=form)
Exemplo n.º 11
0
def add_user():
	form = NewUserForm()
	if form.validate_on_submit():
		user = User()
		form.populate_obj(user)
		db.session.add(user)
		db.session.commit()
		return redirect('/new_post')
	return render_template("add_user.html", form = form)
Exemplo n.º 12
0
def register_user(request):
	if not request.POST:
		form=NewUserForm()
		return render_to_response("form_generic.html",{'form':form},RequestContext(request))
	elif request.POST:
		form=NewUserForm(request.POST)
		if form.is_valid():
			user = User.objects.create_user(username=form.cleaned_data['username'],email=form.cleaned_data['email'],password=form.cleaned_data['password1'])
			return HttpResponseRedirect('/')
Exemplo n.º 13
0
def add_new_user():
    form = NewUserForm()
    if form.validate_on_submit():
        name = form.name.data,
        email = form.email.data,
        phone = form.phone.data,
        mobile_phone = form.mobile_phone.data,
        status = form.status.data
        add_user(name, email, phone, mobile_phone, status)
        flash('User created successfully', 'success')
        return redirect(url_for('users.all_users'))
    return render_template('add_user.html', form=form, title=title)
Exemplo n.º 14
0
def user_add():
    form = NewUserForm()
    if form.validate_on_submit():
        new_user = User(username=form.username.data, password=make_hash(form.password.data), active=form.active.data)
        if new_user:
            db_session.add(new_user)
            db_session.commit()
            flash('Neuer Nutzer erfolgreich angelegt!')
            return redirect(url_for('logged_in'))
        else:
            flash('Neuer Nutzer konnte nicht angelegt werden!')
    return render_template('user_add.jinja', form=form)
Exemplo n.º 15
0
def new_user():
    """Create a new user."""
    form = NewUserForm()
    if form.validate_on_submit():
        user = User(group=form.role.data,
                    first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data,
                    password=form.password.data)
        user.save()
        flash('User {} successfully created'.format(user.full_name()),
              'form-success')
    return render_template('administrator/new_user.html', form=form)
Exemplo n.º 16
0
def add_user():
	form = NewUserForm()
	if form.validate_on_submit(): #valid_on_submit is a subfunction
			user = User()
			#if user submits a valid form, populate the object/class user.
			form.populate_obj(user)
			#Then add to the database and commit
			db.session.add(user)
			db.session.commit()
			#direct them back to the landing page
			return redirect('/')

	return render_template("add_user.html",form = form) #Just shows them the form
Exemplo n.º 17
0
def new_user():
    """Create a new user."""
    form = NewUserForm()
    if form.validate_on_submit():
        user = User(role=form.role.data,
                    first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('User {} successfully created'.format(user.full_name()),
              'form-success')
    return render_template('admin/new_user.html', form=form)
Exemplo n.º 18
0
def new_user_route():
    before_route_load()

    if not sesh.confirm_not_logged_in():
        return redirect(url_for('logout_route'))

    form = NewUserForm()

    if request.method == 'POST':

        if form.validate():
            username = form.username.data
            password = form.password.data
            repeat_password = form.repeat_password.data

            ## additional validation
            ## validate unique username
            username_found = user.find_by_username(username)
            username_in_use = False
            if username_found:
                username_in_use = True
                flash("That username is already taken.", 'error')

            ## if no addtional validation errors:
            if not username_in_use:
                ## insert the user into the DB
                ## pash the hasher and the form
                user.insert_user(hashing=hashing,
                                 username=username,
                                 password=password)

                ## login in the user to the session
                found_user = user.attempt_login(hashing, username, password)

                if found_user:
                    sesh.set_logged_in(True)
                    sesh.set_username(found_user["username"])
                    sesh.set_user_id(str(found_user["_id"]))

                    ## redirect to update user
                    return redirect(url_for('update_user_route'))
                else:
                    flash("Something went wrong creating the account.",
                          'message')

    return render_template('new_user.html',
                           sesh=sesh,
                           form=form,
                           page_title='New User')
Exemplo n.º 19
0
def new_user(request):
    if request.method == 'POST':
        form = NewUserForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            email = form.cleaned_data['email']
            user = User.objects.create_user(username, email, password)
            u = authenticate(username=username, password=password)
            login(request, u)
            return HttpResponseRedirect('/user/%s' % username)
    else:
        form = NewUserForm()
    context = {}
    context['form'] = form
    return render(request, 'registration/new_user.html', context)
Exemplo n.º 20
0
def new_user(request):
    if request.method == 'POST':
        form = NewUserForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            email = form.cleaned_data['email']
            user = User.objects.create_user(username, email, password)
            u = authenticate(username=username, password=password)
            login(request, u)
            return HttpResponseRedirect('/user/%s' % username)
    else:
        form = NewUserForm()
    context = {}
    context['form'] = form
    return render(request, 'registration/new_user.html', context)
Exemplo n.º 21
0
def createUser(request):
	print "** createUser DEBUG LOG**"
	form = NewUserForm(request.POST)
	print 'form set'
	if form.is_valid():
		newUser = form.save()
		newUserProfile = Profile(user=newUser)
		newUserProfile.save()
		print "user '%s' created" % newUser.username
		print '**OK**'
		return HttpResponseRedirect(reverse('home'))
	else:
		form = NewUserForm()
		print 'form reset'
		print '**ERR FORM CREATION FAILED**'
		return render(request, 'signup.html', {'form':form})
Exemplo n.º 22
0
    def post(self):
        form = NewUserForm()

        if request.method == 'POST':

            if form.validate_on_submit():
                user = User.create()
                form.populate_obj(user)
                user.set_password(form.password.data)
                user.save()

                return resp(url_for('UsersView:get', id=user.id), redirect=True,
                            message=gettext('User was succesfully saved'))
            else:
                return resp('admin/users/add.html', form=form, user=None, status=False,
                            message=gettext('Invalid submission, please check the messages below'))

        return resp('admin/users/add.html', form=form, user=None)
Exemplo n.º 23
0
def new_user(request):
    if request.method == 'POST':
        form = NewUserForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('posting_site'))
    else:
        form = NewUserForm()

    context = {
        'form': form,
    }

    return render(
        request,
        'new_user.html',
        context=context,
    )
Exemplo n.º 24
0
def admin_post_op(request):
    """
    Deal with op, dispatches on the op value in order to make way for other
    forms on the admin page in the future.
    
    Returns data to send on to html templates
    (flash_msg, ok_flash_msg, newuserform)
    """
    
    operation = request.POST['op']
    if operation == "newuser":
        newuserform = NewUserForm(request.POST, request.FILES)
        if newuserform.is_valid():
            return _newuser(newuserform, request.FILES)
        else:
            return ("Problem creating new user", None, newuserform)
    else:
        return ("Could not find operation '%s'" % operation, None, None)
Exemplo n.º 25
0
def registration(request):
    if request.user.is_authenticated():
        return redirect(to='profile', permanent=True)

    context = dict(active_tab='registration')
    if request.method == 'POST':
        form = NewUserForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.account = Account()
            user.account.save()
            request.session['registration_completed'] = True
            return redirect(to='login', permanent=True)
        else:
            context['form'] = form
    else:
        context['form'] = NewUserForm()
    return render(request, 'accounts/registration.html', context)
Exemplo n.º 26
0
def new_account(request):
    next = request.GET.get('next', default = '/')
    if request.method == "POST":
        form = NewUserForm(request.POST)
        if form.is_valid():
            form.save()
            user = authenticate(username=request.POST['username'],
                    password=request.POST['password1'])
            login(request, user)
            print next
            return HttpResponseRedirect(next)
        return render_to_response('interface/new_user.html',
                {'form':form},
                context_instance=RequestContext(request))
    form = NewUserForm()
    return render_to_response('interface/new_user.html',
            {'form':form.as_table,
             'path':next},
            context_instance=RequestContext(request))
Exemplo n.º 27
0
def signup():
    """Handle user signup
    Create new user and add to DB"""
    form = NewUserForm()
    
    if form.validate_on_submit():
        try:
            user = User.signup(
                username=form.username.data,
                password=form.password.data,
                email=form.email.data
            )
            db.session.commit()
            flash(f"Welcome to EnergyGuide, {user.username}", "secondary")
        except IntegrityError:
            flash("Username already taken", "danger")
            return render_template('signup.html', form=form)
        login_user(user)
        return redirect("/")
    else:
        return render_template('signup.html', form=form)    
Exemplo n.º 28
0
def signup():
    """Handle user signup."""

    if "username" in session:
        return redirect(f"/users/{session['username']}")

    form = NewUserForm()
   
    if form.validate_on_submit():
        # collects data from the form inputs by user
        username = form.username.data
        password = form.password.data
        email = form.email.data

        user = User.signup(username, password, email)
        db.session.commit()
        session["username"] = user.username
        flash('Welcome to our site!', 'success')
        return redirect(f"/users/{user.username}")
    else:  
        return render_template("signup.html", form=form)
Exemplo n.º 29
0
def user_signup():
    form = NewUserForm()
    this_user = validate_and_signup(form)

    if not this_user:
        flash('Username already taken', 'danger')
        return render_template('/signup_and_login/signup.html', form=form)

    do_login(this_user)
    flash(f"Welcome to MovieBuddy, {this_user.username}", 'success')

    return redirect(f"/users/{this_user.id}")
Exemplo n.º 30
0
def new_user():
    """Create a new user."""
    form = NewUserForm()
    if form.validate_on_submit():
        role_choice = form.role.data.name
        if role_choice == 'Vendor':
            user = Vendor(email=form.email.data,
                          first_name=form.first_name.data,
                          company_name=form.company_name.data,
                          last_name=form.last_name.data,
                          password=form.password.data)
        elif role_choice == 'Merchant':
            user = Merchant(email=form.email.data,
                            first_name=form.first_name.data,
                            company_name=form.company_name.data,
                            last_name=form.last_name.data,
                            password=form.password.data)
        elif role_choice == 'Administrator':
            user = User(role=form.role.data,
                        email=form.email.data,
                        first_name=form.first_name.data,
                        last_name=form.last_name.data,
                        password=form.password.data)
        else:
            # invalid selection for user role
            flash('Invalid role selection', 'form-error')
            return render_template('admin/new_user.html', form=form)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        send_email(user.email,
                   'You Are Invited To Join',
                   'account/email/invite',
                   user=user,
                   user_id=user.id,
                   token=token)
        flash('User {} successfully created'.format(user.full_name()),
              'form-success')
        return redirect(url_for('admin.new_user'))
    return render_template('admin/new_user.html', form=form)
Exemplo n.º 31
0
Arquivo: views.py Projeto: bembu/tidy
def new_user():
    form = NewUserForm()

    if form.validate_on_submit():

        if not user_exists(form.username.data):
            role = models.ROLE_USER
            if form.admin.data == True:
                role = models.ROLE_ADMIN
            u = models.User(username=form.username.data, role=role)
            u.hash_password(form.password.data)

            db.session.add(u)
            db.session.commit()

            flash(u'New user created successfully.', 'alert-success')
            return redirect(url_for("index"))

        else:
            flash(u'Username is taken.', 'alert-danger')

    return render_template("new_user.html", form=form)
Exemplo n.º 32
0
def new_account_setup():
    form = NewUserForm()
    
    if request.method == 'POST':
        if form.validate() == False:
            flash('All fields are required.')
            return render_template('new_account_setup.html', domains_list=settings.list_of_local_domains, domains_tag=settings.local_domain_paths, form=form)
        else:
            gAPI = google_api.gAPI(request.form.get('org_domain'), form.username.data, form.password_alpha.data)
            gAPI.create_new_user(form.givenname.data, form.familyname.data)
            if request.form.get('ADcheckbox') == 'on':
                LDAP.addUser(str(form.username.data), str(form.givenname.data), str(form.familyname.data), str(form.email.data), str(form.password_alpha.data), str(request.form.get('org_name')))
                if request.form.get('hiddenGroupsList') == '':
                    pass
                else:
                    for group in eval(request.form.get('hiddenGroupsList')):
                        group_dn = group[0]
                        user_dn = 'CN=' + str(form.givenname.data) + ' ' + str(form.familyname.data) + ',OU=' + str(request.form.get('org_name')) + ',' + settings.local_DC
                        LDAP.addUsertoGroups(group_dn, user_dn)
            else:
                pass
            return redirect(url_for('home'))
    elif request.method == 'GET':
        return render_template('new_account_setup.html', domains_list=settings.list_of_local_domains, domains_tag=settings.local_domain_paths, form=form, ADorg_list=LDAP.retrieveADGroups())
Exemplo n.º 33
0
def new_user(request):
    if request.method == 'POST': # If the form has been submitted...
        form = NewUserForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            if len(User.objects.filter(username=form.cleaned_data['email'])) == 0:
                email = form.cleaned_data['email']
                password = form.cleaned_data['password']
                first_name = form.cleaned_data['first_name']
                last_name = form.cleaned_data['last_name']

                new_guy = User.objects.create_user(email, email, password)
                new_guy.first_name = first_name
                new_guy.last_name = last_name
                new_guy.save()

                return redirect('/') # Redirect after POST
            else:
                form.non_field_errors = "Email already registered."
    else:
        form = NewUserForm() # An unbound form

    return render(request, 'jsApp/new_user.html', {
        'form':form,
        })