Пример #1
0
def addUser():
    form = CreateAccountForm(request.form)
    if request.method == 'POST' and form.validate():
        # save user in the database
        if session.get('username') is not None:
            app.logger.debug("User is logged in so it must be an admin editing users")
            usertype = form.usertype.data
            app.logger.debug(form.usertype.data)
            cursor = g.db.execute('insert into users(name, username, password, usertype) values(?, ?, ?, ?)',\
            [form.newname.data, form.newusername.data, form.newpassword.data, usertype])
            # log the user in
            g.db.commit()
            app.logger.debug('New user created')
            allUsersQuery = g.db.execute('select * from users')
            allUsers = allUsersQuery.fetchall()
            session['message'] = { 'message': 'User has been added'}
            return redirect(url_for('userOptions'))
        else:
            app.logger.debug("User is not logged in- a new user is being created")
            app.logger.debug("Form field has data")
            usertype = form.usertype.data
            app.logger.debug(form.usertype.data)
            cursor = g.db.execute('insert into users(name, username, password, usertype) values(?, ?, ?, ?)',\
            [form.newname.data, form.newusername.data, form.newpassword.data, usertype])
            # log the user in
            g.db.commit()
            app.logger.debug('New user created')
            session['username'] = form.newusername.data
            return redirect(url_for('userOptions'))
    title = "Add a New User"
    return render_template('adduser.html', form=form, title=title)
Пример #2
0
def addUser():
    form = CreateAccountForm(request.form)
    if request.method == 'POST' and form.validate():
        # save user in the database
        if session.get('username') is not None:
            app.logger.debug(
                "User is logged in so it must be an admin editing users")
            usertype = form.usertype.data
            app.logger.debug(form.usertype.data)
            cursor = g.db.execute('insert into users(name, username, password, usertype) values(?, ?, ?, ?)',\
            [form.newname.data, form.newusername.data, form.newpassword.data, usertype])
            # log the user in
            g.db.commit()
            app.logger.debug('New user created')
            allUsersQuery = g.db.execute('select * from users')
            allUsers = allUsersQuery.fetchall()
            session['message'] = {'message': 'User has been added'}
            return redirect(url_for('userOptions'))
        else:
            app.logger.debug(
                "User is not logged in- a new user is being created")
            app.logger.debug("Form field has data")
            usertype = form.usertype.data
            app.logger.debug(form.usertype.data)
            cursor = g.db.execute('insert into users(name, username, password, usertype) values(?, ?, ?, ?)',\
            [form.newname.data, form.newusername.data, form.newpassword.data, usertype])
            # log the user in
            g.db.commit()
            app.logger.debug('New user created')
            session['username'] = form.newusername.data
            return redirect(url_for('userOptions'))
    title = "Add a New User"
    return render_template('adduser.html', form=form, title=title)
Пример #3
0
def create_account():
    form = CreateAccountForm()
    if form.validate_on_submit():
        formatted_email = format_email(form.email.data)
        hashed_salted_pw = bcrypt.hashpw(form.password.data.encode("utf-8"),
                                         bcrypt.gensalt())

        if User.select().where(User.email == formatted_email).count() > 0:
            flash(f"Account with email {formatted_email} already exists")
            return redirect(url_for("login"))

        new_user = User.create(
            id=uuid.uuid4(),
            email=formatted_email,
            salted_pw=hashed_salted_pw,
            gender=form.gender.data,
            age_range=form.age_range.data,
            language=form.language.data,
        )

        login_user(new_user)

        return redirect(url_for("home"))
    else:
        flash_errors(form)

    return render_template("create_account.html", form=form)
Пример #4
0
def user_youth():
    form = CreateAccountForm()
    if form.validate_on_submit():
        flash(f'Account created for {form.name.data}!', 'success')
        return redirect(url_for('home', _anchor='continue'))
    return render_template('user_youth.html',
                           title='Create Youth Account',
                           form=form)
Пример #5
0
def create_account():
    """Creates user and renders template"""
    check_auth(1)
    form = CreateAccountForm()
    if form.validate_on_submit():
        create_user_account(form.name.data, session['user_id'])
        flash('New account sucsefuly created!', 'success')
        return redirect(url_for('accounts'))
    return render_template('create_account.html', form=form)
Пример #6
0
def create_account_view(request):
    if request.method == 'POST':
        form = CreateAccountForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/account/successful')

    form = CreateAccountForm

    return render(request, 'create_account.html', {'form': form})
Пример #7
0
def create_account():
    if request.method == 'GET':
        return render_template('account_create.html', form=CreateAccountForm())
    else:
        form = CreateAccountForm.from_request(request)
        if form.is_valid():
            account = form.create_account()
            session['user_id'] = account['id']
            return redirect(form.success_url)
        else:
            return render_template('account_create.html', form=form)
Пример #8
0
def sign_up(request):
    if request.method == 'POST' and request.POST.get(
            'password') == request.POST.get('rePassword'):
        form = CreateAccountForm(request.POST)
        if form.is_valid():
            m = form.save()
            try:
                m.save()
            except:
                m = CreateAccount()
                return render(
                    request, 'Sign_up.html',
                    {'form': m
                     })  # There will be a validation error on this page
            dateOpened = datetime.datetime.now()
            date = datetime.datetime.now() + datetime.timedelta(1)
            status = 'Activation Required'
            n = False
            while n == False:
                try:
                    accNum = randint(1000000000, 9999999999)
                    m.accNum = accNum
                    m.save()
                    n = True
                except:
                    pass
            m.accNick = str(accNum)
            m.dateOpened = dateOpened
            m.status = status
            m.date = date
            salt = sha.new(str(random.random())).hexdigest()[:5]
            activation_key = sha.new(salt + str(m.userName)).hexdigest()
            key_expires = date
            mailer = Mail.objects.create(user=m.userName,
                                         email=m.email,
                                         activation_key=activation_key,
                                         date=key_expires)
            mailer.save()
            models.mail_activation(m.userName, m.email, activation_key)
            m.save()
            return HttpResponseRedirect('/Success1')
        else:
            m = CreateAccount()
            return render(
                request, 'Sign_up.html',
                {'form': m})  #There will be a validation error on this page
    else:
        m = CreateAccount()
        return render(request, 'Sign_up.html', {'form': m})
Пример #9
0
def createAccount():
    app.logger.debug('In create account!')
    form = CreateAccountForm(request.form)
    if request.method == 'POST' and form.validate():
        usertype = form.usertype.data
        app.logger.debug(form.usertype.data)
        cursor = g.db.execute('insert into users(name, username, password, usertype) values(?, ?, ?, ?)',\
        [form.newname.data, form.newusername.data, form.newpassword.data, usertype])
        # log the user in
        g.db.commit()
        app.logger.debug('New user created')
        session['username'] = form.newusername.data
        return redirect(url_for('home'))
    title = "Create An Account"
    return render_template('createaccount.html', url="base.html", form=form, title=title)
Пример #10
0
def create_account_page():
    account_form = CreateAccountForm()
    if account_form.validate_on_submit():
        new_account ={
            'Name' : account_form.name.data, 
            'Email' : account_form.email.data, 
            'Address' : 'ABCDEFGHIJKLMNOP', 
            'Pass' : 'TEST'
        }
        # 這裡接create account的邏輯
        new_account ['Address'],new_account ['Pass'] = client.generate_algorand_keypair()
        session['new_account'] = new_account
        flash('Create success')
        return redirect('/createaccount-finished')
    return render_template('/create/account.html', acco_form = account_form)
Пример #11
0
def create_account():
    form = CreateAccountForm()
    if request.method == 'POST':
        ws_cust_id = request.form.get('ws_cust_id')
        ws_acct_type = request.form.get('ws_acct_type')
        ws_amt = request.form.get('ws_amt')

        customer = Customer.query.filter_by(ws_cust_id=ws_cust_id).first()
        if customer:
            account = Account(ws_cust_id=ws_cust_id, ws_acct_type=ws_acct_type)
            account.ws_acct_balance = ws_amt
            account.ws_acct_crdate = datetime.now()
            account.ws_acct_lasttrdate = datetime.now()
            #ws_acct_duration

            db.session.add(account)
            db.session.commit()
            # to update status
            temp_acc = Account.query.order_by(Account.ws_acc_id.desc()).first()
            if temp_acc:
                update_status_account(temp_acc.ws_acc_id, 'created')

            flash("Account creation initiated !", "success")
            return render_template("customer.html",
                                   title="Account created",
                                   create_account=True)
        else:
            flash("Customer Id does not exist !", "danger")

    return render_template("create_account.html",
                           form=form,
                           create_account=True,
                           title='Create Account')
Пример #12
0
def updateUser():
    form = CreateAccountForm(request.form)
    if request.method == 'POST':
        updateName = g.db.execute('update users set name=? where username=? and name=?', \
        [form.newname.data, session['username'], session['name']])
        g.db.commit()
        session['name'] = form.newname.data
    return render_template('updateuser.html', form=form)
Пример #13
0
def createAccount():
    app.logger.debug('In create account!')
    form = CreateAccountForm(request.form)
    if request.method == 'POST' and form.validate():
        usertype = form.usertype.data
        app.logger.debug(form.usertype.data)
        cursor = g.db.execute('insert into users(name, username, password, usertype) values(?, ?, ?, ?)',\
        [form.newname.data, form.newusername.data, form.newpassword.data, usertype])
        # log the user in
        g.db.commit()
        app.logger.debug('New user created')
        session['username'] = form.newusername.data
        return redirect(url_for('home'))
    title = "Create An Account"
    return render_template('createaccount.html',
                           url="base.html",
                           form=form,
                           title=title)
Пример #14
0
def deleteUser(username):
    form = CreateAccountForm(request.form)
    app.logger.debug(username)
    if username == session['username']:
        session['message'] = {'message': 'Logged in user cannot be deleted'}
    else:
        query = g.db.execute('delete from users where username = ?',\
        [username])
        g.db.commit()
        session['message'] = {'message': 'User has been deleted'}
    return redirect(url_for('userOptions'))
Пример #15
0
def create_account():
    #if g.user is not None or 'user_id' not in session:
    #    return redirect(url_for('index'))
    form = CreateAccountForm(request.form)
    if request.method == 'POST':
        if form.validate():
            user = User.query.filter_by(username=form.ca_username.data).first()
            if user is None:
                new_user = User(form.ca_username.data,
                        form.ca_email.data, form.ca_password.data)
                db.session.add(new_user)
                db.session.commit()
                flash('Account Created')
                session['user_id'] = new_user.id
                return redirect(url_for('index'))
            else:
                flash(u"Username can not be used.", 'error')
        else:
            flash_form_errors(form)

    return render_template('create_account.html', create_account_form=form)
Пример #16
0
def create_account():
    #if g.user is not None or 'user_id' not in session:
    #    return redirect(url_for('index'))
    form = CreateAccountForm(request.form)
    if request.method == 'POST':
        if form.validate():
            user = User.query.filter_by(username=form.ca_username.data).first()
            if user is None:
                new_user = User(form.ca_username.data, form.ca_email.data,
                                form.ca_password.data)
                db.session.add(new_user)
                db.session.commit()
                flash('Account Created')
                session['user_id'] = new_user.id
                return redirect(url_for('index'))
            else:
                flash(u"Username can not be used.", 'error')
        else:
            flash_form_errors(form)

    return render_template('create_account.html', create_account_form=form)
Пример #17
0
def sign_up(request):
    if request.method == 'POST' and request.POST.get('password') == request.POST.get('rePassword'):
        form = CreateAccountForm(request.POST)
        if form.is_valid():
            m = form.save()
            try:
                m.save()
            except:
                m = CreateAccount()
                return render(request, 'Sign_up.html', {'form': m})  # There will be a validation error on this page
            dateOpened = datetime.datetime.now()
            date = datetime.datetime.now() + datetime.timedelta(1)
            status = 'Activation Required'
            n =False
            while n == False:
                try:
                    accNum = randint(1000000000, 9999999999)
                    m.accNum = accNum
                    m.save()
                    n = True
                except:
                    pass
            m.accNick = str(accNum)
            m.dateOpened = dateOpened
            m.status = status
            m.date = date
            salt = sha.new(str(random.random())).hexdigest()[:5]
            activation_key = sha.new(salt + str(m.userName)).hexdigest()
            key_expires = date
            mailer = Mail.objects.create(user=m.userName,email=m.email,activation_key=activation_key,date=key_expires)
            mailer.save()
            models.mail_activation(m.userName, m.email, activation_key)
            m.save()
            return HttpResponseRedirect ('/Success1')
        else:
            m = CreateAccount()
            return render(request, 'Sign_up.html', {'form': m}) #There will be a validation error on this page
    else:
        m = CreateAccount()
        return render(request, 'Sign_up.html', {'form': m})
Пример #18
0
def userOptions():
    form = CreateAccountForm(request.form)
    allUsersQuery = g.db.execute('select * from users')
    allUsers = allUsersQuery.fetchall()
    sessionMessage = session.pop('message', [])
    app.logger.debug(sessionMessage)
    if sessionMessage:
        message = sessionMessage['message']
    else:
        message = ''
    return render_template('userOptions.html',
                           allUsers=allUsers,
                           form=form,
                           message=message)
Пример #19
0
def create_account(request):
	if request.method == 'POST':
		create_account_form = CreateAccountForm(request.POST)
		if create_account_form.is_valid():
			user, password = create_account_form.save()
			message = render_to_string('apple/email/account_created.txt', { 'user':user, 'password':password, 'admin_name':settings.ADMINS[0][0] }, context_instance=RequestContext(request))
			if settings.PRODUCTION == True:
				user.email_user("Account Created", message, settings.DEFAULT_FROM_EMAIL)
			else:
				print message

			return HttpResponseRedirect(user.get_absolute_url())
	else:
		create_account_form = CreateAccountForm()
	return render_to_response('apple/create_account.html', { 'create_account_form':create_account_form }, context_instance=RequestContext(request))
Пример #20
0
def editUser(username):
    form = CreateAccountForm(request.form)
    app.logger.debug("Username", username)
    if request.method == 'POST' and username == 'None':
        updateQuery = g.db.execute('update users set name=?, usertype=?, username=? where username=?', \
        [form.newname.data, form.usertype.data, form.newusername.data, session['oldusername']])
        g.db.commit()
        allUsersQuery = g.db.execute('select * from users')
        allUsers = allUsersQuery.fetchall()
        session['oldusername'] = ''
        session['message'] = {'message': 'User has been edited'}
        return redirect(url_for('userOptions'))
    else:
        allUsersQuery = g.db.execute('select * from users')
        allUsers = allUsersQuery.fetchall()
        editUserQuery = g.db.execute('select * from users where username=?', \
        [username])
        editUser = editUserQuery.fetchall()
        form.newname.data = editUser[0]['name']
        form.newusername.data = editUser[0]['username']
        form.usertype.data = editUser[0]['usertype']
        app.logger.debug(editUser[0])
        session['oldusername'] = editUser[0]['username']
    return render_template('edituser.html', editUser=editUser, form=form)
Пример #21
0
 def POST(self): 
     login  = LoginAccountForm()
     create = CreateAccountForm(Request().POST) 
     if create.validate() != True:
         return render('index.mako', login=login, create=create)
     return web.input()
Пример #22
0
def login(request):

    error_messages = []

    #grab the redirect URL if set
    if request.POST.get('next'):
        redirect = request.POST.get('next')
    elif request.POST.get('redirect'):
        redirect = request.POST.get('redirect')
    elif request.GET.get('next'):
        redirect = request.GET.get('next')
    else:
        redirect = request.META.get('HTTP_REFERER', '/')
        if redirect.endswith("/login/"):
            redirect = "/"
    
    
    #Create login and registration forms
    login_form = SigninForm(initial={'next' : redirect})
    registration_form = CreateAccountForm()

    if request.method == 'POST':

        #Existing user is logging in
        if 'login' in request.POST:

            login_form = SigninForm(data=request.POST)
            user = auth.authenticate(username=request.POST['username'], password=request.POST['password'])
            if user is not None:
                if user.is_active:

                    #Log in
                    auth.login(request, user)
                    #set session timeout
                    if 'remember_me' in request.POST:
                        request.session.set_expiry(settings.SESSION_TIMEOUT)

                    return HttpResponseRedirect(redirect)

                else:
                    # Account exists, but not activated                    
                    error_messages.append("This account has not been activated, please check your email and click on the link to confirm your account")

            else:
                # Account not found                  
                error_messages.append("Sorry, but we could not find that username or email address")


        #New user is registering
        elif request.POST.has_key('register'):

            registration_form = CreateAccountForm(data=request.POST)
            print registration_form
            if registration_form.is_valid():
                backend = get_backend(settings.REGISTRATION_BACKEND)             
                new_user = backend.register(request, **registration_form.cleaned_data)

                #redirect
                return HttpResponseRedirect(reverse('registration_complete'))

    else:
        login_form = SigninForm(initial={'next' : redirect})
        registration_form = CreateAccountForm()
        message = None

    return render_to_response('registration/extended_login.html', {'registration_form': registration_form, 'login_form': login_form, 'error_messages': error_messages, 'redirect': redirect}, context_instance = RequestContext(request))