Esempio n. 1
0
def invite_sign_up(request, password=None):
    try:
        invitation = BetaInvitation.objects.get(password=password)
        if invitation.account:
            return render('used_invite.html', request)
    except BetaInvitation.DoesNotExist:
        return HttpResponseNotFound()

    form = None
    message = None
    if request.method == 'GET':
        if invitation.beta_requester:
            form = forms.SignUpForm(
                initial={'email': invitation.beta_requester.email})
        else:
            form = forms.SignUpForm()
    else:
        form = forms.SignUpForm(data=request.POST)
        if form.is_valid():
            form_data = form.cleaned_data
            try:
                do_sign_up(request, form_data, invitation)
                return HttpResponseRedirect(request.GET.get('next') or '/')
            except IntegrityError, e:
                message = 'Email already exists.'
Esempio n. 2
0
def sign_up(request, package=None):
    account_package = None

    if package:
        account_package = Package.objects.get(code=package)

    if request.user.is_authenticated():
        account = request.user.get_profile().account
        if account.payment_informations.count():
            raise Http404
        else:
            account.apply_package(account_package)
            return HttpResponseRedirect(reverse('dashboard'))

    form = None
    message = None
    if request.method == 'GET':
        form = forms.SignUpForm()
    else:
        form = forms.SignUpForm(data=request.POST)
        if form.is_valid():
            form_data = form.cleaned_data
            try:
                do_sign_up(request, form_data, package=account_package)
                return HttpResponseRedirect(request.GET.get('next') or '/')
            except IntegrityError, e:
                message = 'Email already exists.'
Esempio n. 3
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = forms.SignUpForm(request.form)
    if form.validate_on_submit():
        error = None
        username = form.username.data
        password = form.password.data
        re_entered_password = form.re_password.data
        email = form.email.data
        if password != re_entered_password:
            error = 'Passwords do not match'
            return render_template('signup.html',
                                   error=error,
                                   form=form,
                                   title='Sign Up')
        user = User.User(username)
        if user.insert_new_user(password, email):
            user.find_id()
            login_user(user)
            return redirect(url_for('index'))
        else:
            error = 'Username taken'
            return render_template('signup.html',
                                   error=error,
                                   form=form,
                                   title='Sign Up')
    return render_template('signup.html', form=form, title='Sign Up')
Esempio n. 4
0
def index():
    if login.current_user.is_authenticated():
        return login.redirect('/dashboard')

    # Create the forms
    sign_up_form = forms.SignUpForm()
    sign_in_form = forms.SignInForm()

    if flask.request.method == 'POST' and sign_up_form.validate_on_submit():
        new_user = models.User(
           first_name=sign_up_form.first_name.data,
           last_name=sign_up_form.last_name.data,
           email=sign_up_form.email.data,
           password=bcrypt.generate_password_hash(sign_up_form.password.data),
        )

        db.session.add(new_user)
        db.session.commit()

        return flask.redirect(flask.url_for('dashboard'))

    if flask.request.method == 'POST' and sign_in_form.validate_on_submit():
        user = models.User.query.filter(
            models.User.email == sign_in_form.user_email.data).first()
        login.login_user(user)
        if (bcrypt.check_password_hash(user.password,
                sign_in_form.user_password.data)):
            return flask.redirect(flask.url_for('dashboard'))

    return flask.render_template('home.epy', sign_up_form=sign_up_form,
        sign_in_form=sign_in_form, user=login.current_user)
Esempio n. 5
0
def signup():
    form = forms.SignUpForm()
    if form.validate_on_submit():
        password = form.password.data
        first_name = form.first_name.data
        last_name = form.last_name.data
        email = form.email.data
        gender = form.gender.data
        nationality = form.nationality.data
        passport_number = form.passport_number.data
        phone_number = form.phone_number.data
        age = form.age.data
        account_no = form.account_no.data
        discount = 0
        flyer_points = 0
        cur = mysql.connection.cursor()

        cur.execute(
            "INSERT INTO customers( first_name, last_name, email, gender, password, phone_number, nationality, age, flyer_points, account_number, discount, passport_number ) VALUES (%s, %s, %s,%s, %s, %s, %s, %s, %s,%s, %s, %s)",
            (first_name, last_name, email, gender, password, phone_number,
             nationality, age, flyer_points, account_no, discount,
             passport_number))

        mysql.connection.commit()
        cur.close()
        return "Successfully Signed up!"
    else:
        return render_template("signup.html", form=form)
Esempio n. 6
0
def posts(id=None):
    sign_up_form = forms.SignUpForm()
    sign_in_form = forms.SignInForm()

    if sign_up_form.validate_on_submit():
        handle_signup(sign_up_form)

    elif sign_in_form.validate_on_submit():
        handle_signin(sign_in_form)

    if id == None:
        posts = models.Post.select().limit(100)
        return render_template('posts.html', posts=posts)
    else:
        post_id = int(id)
        post = models.Post.get(models.Post.id == post_id)
        comments = post.comments
        form = forms.CommentForm()
        if form.validate_on_submit():
            models.Comment.create(user=g.user._get_current_object(),
                                  commentText=form.commentText.data,
                                  post=post)

            return redirect("/posts/{}".format(post_id))

        return render_template('post.html',
                               post=post,
                               form=form,
                               comments=comments,
                               sign_in_form=sign_in_form,
                               sign_up_form=sign_up_form)
Esempio n. 7
0
def index():
    form = forms.LoginForm()
    setForm = forms.SignUpForm()
    if request.method=='POST' and request.form['btn'] == 'log in':
        email = form.email.data
        password = cipher_suite.encrypt(form.password.data.encode())
        user = User.get_by_email(email)
        if user is not None and user.check_password(password):
            login_user(user, False)
            return redirect(url_for('dashboard'))
        else:
            flash("Incorrect Email or Password")
            #return redirect(url_for('index'))
    elif request.method=='POST' and request.form['btn'] == 'Sign Up':
        print("IN SIGNUP")
        if validateSignUp():
            print("Creating User")
            user = User(id = db.session.query(User).count() + 1,
                        email = setForm.setEmail.data,
                        eid = setForm.setEID.data,
                        firstName = setForm.firstName.data,
                        lastName = setForm.lastName.data,
                        password = setForm.setPassword.data,
                        ret = 0,
                        score = 0,
                        dues = 0,
                        atLatestMeeting = False,
                        rowOnSheet = 0, 
                        attendance = 0,
                        analyst = None)
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('index'))
        return render_template('index.html', form=form, setForm=setForm, login="******", signup="signup-show", login_active="", signup_active="active")
    return render_template('index.html', form=form, setForm=setForm, login="******", signup="signup", login_active="active", signup_active="")
Esempio n. 8
0
def register():
    # Access SignUpForm from forms.py
    form = forms.SignUpForm()

    if form.validate_on_submit():
        # Sets variable filename to image file of uploaded 'profile_image' from form
        # filename = images.save(request.files['profile_image'])
        # Sets variable url to change image url to match filename
        # url = images.url(filename)

        # Cloudinary image upload
        # cloudinary.uploader.upload(request.FILES['file'])

        # Calls method 'create_user' as defined in models.py to create a user in database
        models.User.create_user(
            username=form.username.data,
            email=form.email.data,
            password=form.password.data,
            location=form.location.data
            #  image_filename=filename,
            # image_url=url
            # image=form.profile_image.data
            )
        
        # Gets newly created user from the database by matching username in the database to username entered in the form
        user = models.User.get(models.User.username == form.username.data)
        # Creates logged in session
        login_user(user)
        flash('Thank you for signing up', 'success')
        # Pass in current/logged in user as parameter to method 'profile' in order to redirect user to profile after signing up
        return redirect(url_for('profile', username=user.username))

    # Initial visit to this page renders the Sign Up template with the SignUpForm passed into it
    return render_template('signup.html', form=form)
Esempio n. 9
0
def signup():
    form = forms.SignUpForm()
    if form.validate_on_submit():
        flash("You've successfully registered!", "success")
        models.User.create_user(username=form.username.data,
                                email=form.email.data,
                                password=form.password.data)
        return redirect(url_for('index'))
    return render_template('signup.html', form=form)
Esempio n. 10
0
def register():
    """Link and place for registration"""
    form = forms.SignUpForm()
    if form.validate_on_submit():
        models.User.create_user(email=form.email.data,
                                password=form.password.data)
        flash("Thanks for registering!")
        return redirect(url_for('index'))
    return render_template('register.html', form=form)
Esempio n. 11
0
def signup():
    form = forms.SignUpForm()
    if form.validate_on_submit():
        flash('Sign up Success!', 'success')
        models.User.create_user(username=form.username.data,
                                email=form.email.data,
                                password=form.password.data,
                                location=form.location.data)
        return redirect(url_for('landing'))
    return render_template('signup.html', title='Sign Up', form=form)
Esempio n. 12
0
def signup():
    form = f.SignUpForm()
    if form.validate_on_submit():
        new_user = {
            "id": len(users) + 1,
            "full_name": form.full_name.data,
            "email": form.email.data,
            "password": form.password.data
        }
        users.append(new_user)
        print(new_user)
        return redirect("/")
    return render_template("signup.html", form=form)
Esempio n. 13
0
def signup():
    form = forms.SignUpForm()
    if form.validate_on_submit():
        models.User.create_user(username=form.username.data,
                                email=form.email.data,
                                password=form.password.data)
        user = models.User.get(models.User.username == form.username.data)
        login_user(user)
        name = user.username
        print('hello')
        return redirect(url_for('dash'))

    return render_template('signup.html', form=form)
Esempio n. 14
0
def signup():
    """Registers new user if they don't already exist"""

    form = forms.SignUpForm()
    if form.validate_on_submit():
        models.User.create_user(
            username=form.username.data,
            email=form.email.data,
            password=form.password.data,
        )
        flash("Yay! You registered!")
        return redirect(url_for("login"))
    return render_template("signup.html", form=form)
Esempio n. 15
0
def signup():
    form = forms.SignUpForm(request.form)
    if current_user.is_authenticated:
        logout()
        return render_template('signup.html', title='Sing Up', form=form)
    if request.method == 'POST' and form.validate():
        user = User(username=form.username.data, password=form.password.data)
        db.session.add(user)
        db.session.commit()
        login_user(user)
        flash('Hello, %s.' % current_user.username)
        flash('Nice to meet you.')
        return redirect('/')
    return render_template('signup.html', title='Sign Up', form=form)
Esempio n. 16
0
def index():
    neighborhoods = models.Neighbor.select()
    sign_up_form = forms.SignUpForm()
    sign_in_form = forms.SignInForm()

    if sign_up_form.validate_on_submit():
        handle_signup(sign_up_form)

    elif sign_in_form.validate_on_submit():
        handle_signin(sign_in_form)

    return render_template('auth.html',
                           neighborhoods=neighborhoods,
                           sign_up_form=sign_up_form,
                           sign_in_form=sign_in_form)
Esempio n. 17
0
def index():
    log_in_form = forms.SignInForm()
    sign_up_form = forms.SignUpForm()
    parkings = models.Parking.select()

    if sign_up_form.validate_on_submit():
        handle_signup(sign_up_form)

    elif log_in_form.validate_on_submit():
        handle_login(log_in_form)

    return render_template('auth.html',
                           sign_up_form=sign_up_form,
                           log_in_form=log_in_form,
                           parkings=parkings)
Esempio n. 18
0
def _get_started_step2(request, plan):
    message = None
    data = request.POST if request.method == 'POST' else None
    account = None
    package = Package.objects.get(code=plan)
    if request.user.is_authenticated():
        sign_up_form = None
        account = request.user.get_profile().account
        account.apply_package(package)
        account.save()
        if package.base_price > 0:
            payment_form = forms.PaymentInformationForm(data=data)
        else:
            return _get_started_step3(request)
    else:
        sign_up_form = forms.SignUpForm(data=data)
        if package.base_price > 0:
            payment_form = forms.PaymentInformationForm(data=data)
        else:
            payment_form = None

    if data:
        sign_up_ok = sign_up_form is None or sign_up_form.is_valid()
        payment_ok = payment_form is None or payment_form.is_valid()
        if sign_up_ok and payment_ok:
            if sign_up_form is not None:
                form_data = sign_up_form.cleaned_data
                try:
                    account = do_sign_up(request, form_data, package)
                    sign_up_form = None
                except IntegrityError, e:
                    message = 'Email already exists.'
            if message is None and payment_form is not None:
                form_data = payment_form.cleaned_data
                try:
                    process_payment_information(account, form_data)
                    account.status = Account.Statuses.operational
                    account.save()

                    mail.report_new_account(account)

                    return _get_started_step3(request)
                except BillingException, e:
                    message = e.msg
            if message is None:
                return _get_started_step3(request)
Esempio n. 19
0
def validateSignUp():
    setForm = forms.SignUpForm()
    ok = True
    if User.query.filter_by(email=setForm.setEmail.data).first():
        flash("User with email already exists")
        ok = False
    if setForm.setPassword.data != setForm.setPassword2.data:
        flash("Passwords do NOT match")
        ok = False
    if (setForm.setEmail.data)[-10:] != "utexas.edu":
        flash("Must use utexas.edu email")
        ok = False
    if len(setForm.setPassword.data) < 6:
        flash("Password must be atleast six characters long")
        ok = False
    if not setForm.setEmail.data or not setForm.firstName.data or not setForm.lastName.data or not setForm.setPassword.data:
        flash("All fields are required")
        ok = False
    return ok
Esempio n. 20
0
def sign_up():

    form_s = forms.SignUpForm()

    # sign up
    if form_s.is_submitted():
        result = request.form
        # check credentials meet constraints
        values = list(result.values(
        ))  # 0 = first_name, 1 = email, 2 = username, 3 = password

        vals_copy = copy.deepcopy(values)
        values[0] = vals_copy[1].encode('ascii')
        values[1] = vals_copy[3].encode('ascii')
        values[2] = vals_copy[0].encode('ascii')
        values[3] = vals_copy[2].encode('ascii')
        values[4] = vals_copy[4].encode('ascii')

        if sql_inj(values[0]) or sql_inj(values[1]) or sql_inj(
                values[2]) or sql_inj(values[3]):
            return 'No SQL injection for you good sir.'

        if values[0] == '' or values[1] == '' or values[2] == '' or values[
                3] == '':
            return 'You cannot enter blank values for any of the login fields'

        if len(values[0]) > 20 or len(values[1]) > 40 or len(
                values[2]) > 20 or len(values[3]) > 40:
            return 'Please enter shorter entries for these fields.'

        db_result = g.conn.execute('SELECT * FROM Users WHERE username=\'' +
                                   values[2] + '\' OR email=\'' + values[1] +
                                   '\'')
        db_result = db_result.fetchall()
        if not len(db_result) == 0:
            return 'Invalid sign up attempt - non unique username or email.'
        g.conn.execute(' '.join(
            ('INSERT INTO Users (firstname, email, username, password)',
             'VALUES (\'' + values[0] + '\', \'' + values[1] + '\', \'' +
             values[2] + '\', \'' + values[3] + '\')')))

    return render_template('signup.html', form=form_s)
Esempio n. 21
0
def neighborpage(neighborid):
    sign_in_form = forms.SignInForm()
    sign_up_form = forms.SignUpForm()
    neighbor_model = models.Neighbor.get_by_id(int(neighborid))
    posts = models.Post.select().where(
        models.Post.neighbor_id == int(neighborid))

    if sign_up_form.validate_on_submit():
        handle_signup(sign_up_form)

    elif sign_in_form.validate_on_submit():
        handle_signin(sign_in_form)

    form = forms.PostForm()
    if form.validate_on_submit():
        models.Post.create(user=g.user._get_current_object(),
                           title=form.title.data,
                           text=form.text.data,
                           address=form.address.data,
                           imgUrl=form.imgUrl.data,
                           category=form.category.data,
                           neighbor=neighbor_model)
        return redirect("/{}".format(neighborid))

    return render_template('posts.html',
                           neighbor=neighbor_model,
                           sign_in_form=sign_in_form,
                           sign_up_form=sign_up_form,
                           posts=posts,
                           form=form,
                           post={
                               "title": "",
                               "text": "",
                               "address": "",
                               "imgUrl": "",
                               "category": ""
                           })
Esempio n. 22
0
def register():
    form = forms.SignUpForm()
    if form.validate_on_submit():
        flash("Thanks for registering!")
        models.User.new(email=form.email.data, password=form.password.data)
    return render_template('register.html', form=form)
Esempio n. 23
0
def signUp(request):
    """
      Sign up
    """
    #Process Registration information
    if request.method == 'POST':
        #bound the form
        form = forms.SignUpForm(request.POST)
        if form.is_valid():
            #place form data into query dict for easier access
            formData = QueryDict(request.body)

            #check for teacher email unqiueness
            if CityDigitsUser.doesUsernameExist(formData.get('email')):
                #add error and return
                errors = form._errors.setdefault("email", ErrorList())
                errors.append(u"Email already Exists")
                return render_to_response(
                    'signup.html', {'form': form},
                    context_instance=RequestContext(request))

            #create entities
            school = School.objects.create(
                name=formData.get('schoolName'),
                address=formData.get('schoolAddress'),
                city=formData.get('schoolCity'),
                state=formData.get('schoolState'))
            teacher = Teacher.objects.create(
                firstName=formData.get('firstName'),
                lastName=formData.get('lastName'),
                email=formData.get('email'),
                className=formData.get('className'),
                school=school)
            school.save()
            teacher.save()
            #create auth user for teacher
            cityUser = CityDigitsUser(
                role="TEACHER",
                username=teacher.email,
                password=MembershipService.encryptPassword(
                    teacher.email, formData.get('password')),
                entityId=teacher.id)
            cityUser.save()

            #create teams and students entities
            teamIdx = 0
            print(formData)
            for teamName in formData.getlist('team_name[]'):
                teamIdx = teamName.split('_')[1]
                teamName = teamName.split('_')[0]
                team = Team.objects.create(name=teamName, teacher=teacher)
                team.save()
                #add students to team
                studentIdx = 0
                for studentName in formData.getlist("student_name[%s][]" %
                                                    teamIdx):
                    #get password
                    password = MembershipService.encryptPassword(
                        studentName,
                        formData.getlist("student_password[%s][]" %
                                         teamIdx)[studentIdx])
                    #get name
                    student = Student.objects.create(firstName=studentName,
                                                     team=team)
                    student.save()
                    #create auth user for student
                    print "student password: "******"STUDENT",
                                              username=student.firstName,
                                              password=password,
                                              entityId=student.id)
                    authUser.save()
                    #update index
                    studentIdx = studentIdx + 1

                #updated team index
                # teamIdx = teamIdx + 1

            #return response
            json_data = json.dumps({"HTTPRESPONSE": 200})
            return HttpResponse(json_data, mimetype="application/json")
        else:
            #form invalid
            #return and display errors
            return render_to_response('signup.html', {'form': form},
                                      context_instance=RequestContext(request))
        pass
    elif request.method == 'GET':
        #Load Sign up form
        form = forms.SignUpForm()
        return render_to_response('signup.html', {'form': form},
                                  context_instance=RequestContext(request))
Esempio n. 24
0
def register():
    form = forms.SignUpForm()
    return render_template('register.html', form=form)