예제 #1
0
def signup():
  form = SignupForm()
  logform = LoginForm()
  if request.method == "POST":
    #print(form.validate())
    if form.validate() == False:
      #print("here")
      return render_template('/signup.html', form=form)
      #return 'Error'
    else:
      #print("in else")
      newuser = User(form.user_name.data, form.first_name.data, form.last_name.data, form.email.data, form.password.data)
      db.session.add(newuser)
      db.session.commit()
      return render_template('/login.html',form=logform)
    return render_template('/signup.html')
예제 #2
0
def pub_create():
    pubform = PubMqttTopicsForm()
    form = SignupForm()
    if request.method == 'GET':
        return render_template('pubCreate.html', form=form, pubform=pubform)
    elif request.method == 'POST':
        if pubform.validate_on_submit():
            newPubTopic = pub_mqtt_topics(pubform.topic.data, pubform.qos.data,
                                          pubform.retain.data)
            db.session.add(newPubTopic)
            db.session.commit()
            return redirect('/pub/view')
        else:
            return "Invalid Data Filed in Form"
    else:
        return "Invalid Form"
예제 #3
0
def signup():
    form = SignupForm()
    if request.method == 'GET':
        return render_template('signup.html', form=form)
    elif request.method == 'POST':
        if form.validate_on_submit():
            if User.query.filter_by(email=form.email.data).first():
                return "Email address already exists"
            else:
                newuser = User(form.email.data, form.password.data)
                db.session.add(newuser)
                db.session.commit()
                # login_user(newuser)
                return "User created!!!"
        else:
            return "Form didn't validate"
예제 #4
0
def example_form():
    form = SignupForm()

    if form.validate_on_submit():
        # We don't have anything fancy in our application, so we are just
        # flashing a message when a user completes the form successfully.
        #
        # Note that the default flashed messages rendering allows HTML, so
        # we need to escape things if we input user values:
        flash('Hello, {}. You have successfully signed up'.format(
            escape(form.name.data)))

        # In a real application, you may wish to avoid this tedious redirect.
        return redirect(url_for('.index'))

    return render_template('signup.html', form=form)
예제 #5
0
def modbus_edit():
    form = SignupForm()
    modbusform = ModbusEditForm()
    if request.method == 'POST':
        if modbusform.validate_on_submit():
            modbus_data = modbus_parameters.query.get(1)
            if not modbus_data == None:
                modbus_data.modbus_ip = modbusform.modbus_ip.data
                modbus_data.modbus_port = modbusform.modbus_port.data
                db.session.commit()
            elif modbus_data == None:
                modbus_data = modbus_parameters(modbusform.modbus_ip.data,
                                                modbusform.modbus_port.data)
                db.session.add(modbus_data)
                db.session.commit()
            return redirect('/settings/view')
예제 #6
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        try:
            hashed_password = generate_password_hash(form.password.data,
                                                     method='sha256')
            new_user = User(username=form.username.data,
                            email=form.email.data,
                            password=hashed_password)
            db.session.add(new_user)
            db.session.commit()
            return render_template(signupTemplate, form=form, success=True)
        except IntegrityError as e:
            return render_template(signupTemplate, form=form, error=e)

    return render_template(signupTemplate, form=form)
예제 #7
0
def signup():
    form = SignupForm()

    if request.method == "POST":
        if form.validate() == False:
            return render_template("signup.html", form=form)
        else:
            newuser = User(form.first_name.data, form.last_name.data, form.email.data, form.password.data)
            db.session.add(newuser)
            db.session.commit()

            session["email"] = newuser.email
            return redirect(url_for("home"))

    elif request.method == "GET":
        return render_template("signup.html", form=form)
예제 #8
0
def login():
    form = LoginForm()
    if request.method == 'POST' and form.validate_on_submit():
        user = app.config['USERS_COLLECTION'].find_one(
            {"_id": form.username.data})
        if user and User.validate_login(user['password'], form.password.data):
            user_obj = User(user['_id'])
            login_user(user_obj)
            flash("Logged in successfully!", category='success')
            next = request.args.get('next')
            return redirect(next or url_for("posts"))
        flash("Wrong username or password!", category='error')
    return render_template('login.html',
                           title='login',
                           form=form,
                           signup_form=SignupForm())
예제 #9
0
def signup():
    if 'email' not in session:
        return redirect(url_for('home'))
    form = SignupForm()
    if form.validate_on_submit():
        newuser = User(form.first_name.data, form.last_name.data, form.email.data, form.password.data)
        db.session.add(newuser)
        db.session.commit()

        session['email'] = newuser.email
        return redirect(url_for('home'))

    elif request.method == 'GET':
        return render_template('signup.html', form=form)
    else:
        return render_template('signup.html', form=form)
예제 #10
0
파일: routes.py 프로젝트: huchenme/flitter
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        # create an user instance not yet stored in the database
        user = User(name=form.name.data, username=form.username.data, \
          password=form.password.data)
        # Insert the record in our database and commit it
        db.session.add(user)
        db.session.commit()
        login_user(user, remember=True)
        # flash will display a message to the user
        flash('Thanks for signing up', 'success')
        # redirect user to the 'home' method of the user module.
        return redirect(url_for('home'))
    return render_template("index.html",
                           signup_form=form,
                           login_form=LoginForm())
예제 #11
0
def signup():
    form = SignupForm()
    if request.method == 'POST':
        if form.validate() == False:
            return render_template('signup.html', form=form)
        else:
            print("Creating user")
            newuser = User(form.username.data, form.firstname.data,
                           form.lastname.data, form.email.data, form.uin.data,
                           form.password.data)
            db.session.add(newuser)
            db.session.commit()
            session["email"] = newuser.email
            return redirect(url_for("home"))

    elif request.method == 'GET':
        return render_template('signup.html', form=form)
예제 #12
0
파일: app.py 프로젝트: mfierro31/star_tours
def signup():
    form = SignupForm()

    if g.user:
        flash('Please log out first if you want to create a new account.',
              'danger')
        return redirect('/')

    if form.validate_on_submit():
        # Make a list of values from the form.data dict and splat them out into User.signup instead of having to enter
        # every field's data one by one
        form_data = form.data
        form_data.pop('csrf_token')
        form_data = form_data
        form_data = [v for v in form_data.values()]

        new_user = User.signup(*form_data)

        if type(new_user) == list:
            # Logic to check the errors.  If it's for both username and email, we want to display both error messages, if just one,
            # we want to display the correct error message for the correct field
            if len(new_user) == 2:
                form.username.errors = [new_user[0]]
                form.email.errors = [new_user[1]]
                # Notice we have to use render_template instead of redirect here, otherwise our errors won't show up
                # This is because with redirect, you can't pass in the form to it.  And since errors are located in form, they
                # don't show up
                return render_template('signup.html', form=form)
            elif 'username' in new_user[0]:
                form.username.errors = [new_user[0]]
                return render_template('signup.html', form=form)
            elif 'email' in new_user[0]:
                form.email.errors = [new_user[0]]
                return render_template('signup.html', form=form)
        else:
            db.session.add(new_user)
            db.session.commit()

            do_login(new_user)

            flash(
                f'Welcome, {new_user.first_name}!  Successfully created your account!',
                'success')
            return redirect('/')
    else:
        return render_template('signup.html', form=form)
예제 #13
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        name = form.name.data
        email = form.email.data
        arrival = datetime.strptime(form.arrival_date.data.strftime('%x'),
                                    "%m/%d/%y").date()
        departure = datetime.strptime(form.departure_date.data.strftime('%x'),
                                      "%m/%d/%y").date()

        unique_id = reserve_dates(name, email, arrival, departure, session)
        arrival_str = datetime.strftime(arrival, '%m/%d/%y')
        departure_str = datetime.strftime(departure, '%m/%d/%y')

        return "Unique Registration ID: {} for {} to {}".format(
            unique_id, arrival_str, departure_str)
    return render_template('signup.html', form=form)
예제 #14
0
    def signup(self):
        form = SignupForm()

        if request.method == 'POST':
            if form.validate() == False:
                return render_template('signup.html', form=form)
            else:
                session['student'] = {}
                newStudent = Student()
                id = newStudent.add(form.name.data, form.email.data,
                                    form.password.data, form.phone.data)
                session['student']['id'] = id
                session['student']['name'] = form.name.data
                session['student']['email'] = form.email.data
                return redirect(url_for('select_interests'))

        return render_template('signup.html', form=form)
예제 #15
0
def signup():

    form = SignupForm()

    if request.method == "POST":
        if form.validate() == False:
            return render_template('signup.html', form=form)
        else:
            models.Student.edit(form.netid.data, form.name.data)
            if models.Student.edit(form.netid.data, form.name.data) == -1:
                return render_template('signup.html', form=form)

            session['netid'] = form.netid.data
            return render_template('home.html')

    elif request.method == "GET":
        return render_template('signup.html', form=form)
예제 #16
0
def signup():
    form = SignupForm()

    if form.validate_on_submit():
        user = User(email=form.email.data.lower(), created_at=datetime.datetime.now())
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()

        session['user_id'] = user.id
        session['email'] = user.email
        return redirect(url_for('index'))

    elif form.errors:
        flash("Error creating account")

    return render_template("signup.html", form=form)
예제 #17
0
def signup():
    form = SignupForm()

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('signup.html', form=form)
        else:
            newUser = Users(form.firstname.data, form.lastname.data,
                            form.email.data, form.password.data,
                            form.address.data)
            db.add(newUser)
            db.commit()
            session['email'] = newUser.email
            return redirect(url_for('profile'))

    elif request.method == 'GET':
        return render_template('signup.html', form=form)
예제 #18
0
def signup():
    if session['user_email']:
        flash('you are already signed up')
        return redirect(url_for('login'))
    form = SignupForm()
    if form.validate_on_submit():
        user_email = User.query.filter_by(email=form.email.data).first()
        if user_email is None:
            user = User(form.name.data, form.email.data, form.password.data)
            db.session.add(user)
            db.session.commit()
            session['user_email'] = form.email.data
            session['user_name'] = form.name.data
            return redirect(url_for('login'))
        else:
            return render_template('error1.html')
    return render_template('signup.html', form=form)
예제 #19
0
def signup():
  if 'email' in session:
      return redirect(url_for('home'))

  form = SignupForm()

  if request.method == "POST":
    if form.validate() == False:
      return render_template('signup.html', form=form)
    else:
      newuser = User(form.first_name.data, form.last_name.data, form.email.data, form.password.data)
      db.session.add(newuser)
      db.session.commit()
      return 'Success!'

  elif request.method == "GET":
    return render_template('signup.html', form=form)
예제 #20
0
def login():
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('index'))
    login_form = LoginForm()
    signup_form = SignupForm()
    if login_form.validate_on_submit():
        user = User.query.filter_by(username=login_form.username.data).first()
        if user:
            # TODO: make password check more secure
            if user.password == login_form.password.data:
                login_user(user, remember=login_form.remember_me.data)
                return redirect(request.args.get('next') or url_for('index'))
        flash('Invalid username or password. Try again.')
        return redirect(url_for('login'))
    return render_template("partials/login.html",
                           login_form=login_form,
                           signup_form=signup_form)
예제 #21
0
def signup_ajax(request):
    form = SignupForm(request.POST)

    if not form.is_valid():
        return http.HttpResponse(400)

    email = form.cleaned_data['email']
    signup_questions = request.POST.dict()
    del signup_questions['email']

    signup_model.create_or_update_signup(email, signup_questions)
    response = http.HttpResponse(200)
    response['Access-Control-Allow-Origin'] = '*'
    response['Access-Control-Allow-Methods'] = 'POST, OPTIONS'
    response['Access-Control-Allow-Headers'] = '*'
    response['Access-Control-Max-Age'] = '1728000'
    return response
예제 #22
0
def signup():
    """This function renders signup form to signup html template
    and handles the POST request from the form"""

	# If sign in form is submitted
    form = SignupForm(request.form)

    # Verify the signup in form
    if form.validate_on_submit():
        user = User(name= form.name.data, email=form.email.data,
            id_no=form.id_no.data, password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('You are now a Library valid User')
        return redirect(url_for('user_login'))
    flash('Enter unique Name, Email and ID Number')
    return render_template('signup.html', form=form)
예제 #23
0
파일: app.py 프로젝트: PeterJohnsen/tweeter
def index(username=None):
    login_form = LoginForm()
    if username or current_user.is_authenticated:
        tweet_form = TweetForm()
        if username:
            user = models.User.get(models.User.username**username)
        else:
            user = current_user._get_current_object()
        return render_template('dashboard.html',
                               user=user,
                               login_form=login_form,
                               tweet_form=tweet_form)

    signup_form = SignupForm()
    return render_template('index.html',
                           signup_form=signup_form,
                           login_form=login_form)
예제 #24
0
def signup():
    form = SignupForm()

    if request.method == "POST":
        if form.validate() == False:
            return render_template('signup.html', form=form)
        else:
            newuser = User(form.first_name.data, form.last_name.data,
                           form.email.data, form.password.data)
            #   newuser = User('john', 'smith', '*****@*****.**', 'abcd')

            db.session.add(newuser)
            db.session.commit()
            return 'Success!'

    elif request.method == "GET":
        return render_template('signup.html', form=form)
예제 #25
0
def signup():

    form = SignupForm()
    if form.validate_on_submit():
        u = form
        user = User(firstname=u.firstname.data,
                    lastname=u.lastname.data,
                    username=u.username.data,
                    email=u.email.data,
                    password=u.password.data,
                    is_attempting=False)
        user.set_password(u.password.data)
        db.session.add(user)
        db.session.commit()
        flash("You have registered sucessfully!!!", "success")
        return redirect(url_for('login'))
    return render_template('signup.htm', form=form)
예제 #26
0
def login():
    form = SignupForm()
    if request.method == 'GET':
        return render_template('login.html', form=form)
    elif request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(email=form.email.data).first()
            if user:
                if user.password == form.password.data:
                    login_user(user)
                    return "User logged in"
                else:
                    return "Wrong password"
            else:
                return "user doesn't exist"
    else:
        return "form not validated"
예제 #27
0
def register():
    form = SignupForm()
    if form.validate_on_submit():
        user = Users(
            form.username.data,
            form.password.data,
            form.email.data,
            1,
        )
        db.session.add(user)
        db.session.commit()
        confirm_user(form.username.data, form.email.data)
        flash(u'Check your email to activate your account.')
        return redirect(url_for('index'))

    flash(u'Create your flaskCamel account')
    return render_template('register.html', form=form)
예제 #28
0
def signup():
	form = SignupForm()  
	if request.method == 'POST':
		if form.validate() == False:
		  return render_template('signup.html', form=form)
		else:   
		  newuser = User(form.firstname.data, form.lastname.data, form.email.data, form.password.data)
		  address = Address(address=form.address.data)
		  newuser.addresses.append(address)
		  db.session.add(newuser)
		  db.session.add(address)#use relationship here
		  db.session.commit() 
		  session['email'] = newuser.email
		  return redirect(url_for('profile'))
      
	elif request.method == 'GET':
		return render_template('signup.html', form=form)  
예제 #29
0
파일: views.py 프로젝트: vtzk/dodo.md
def signup():
    form = SignupForm(request.form, csrf_enabled=True)
    print request.method
    if request.method == 'POST':

        user_type = form.user_type_id.data

        print "method POST - save data to database"
        print form.parola.data
        form_tasks = Users(nume=form.nume.data,
                           email=form.email.data,
                           parola=generate_password_hash(form.parola.data),
                           user_type=form.user_type_id.data)
        db.session.add(form_tasks)
        db.session.commit()
        return redirect('/')
    return render_template("signup.html", form=form)
예제 #30
0
    def testPersistency(self):
        """
        Test if an user had been saved to the database, and its properties are saved well
        (i.e. the field values correspond to those of the fixture)
        """
        form_data = self.f_valid_form_data.copy()
        form = SignupForm(self.f_postal_address_form, self.f_postal_address_form, data=form_data)
        self.assertEqual(form.is_valid(), True)
        form.save()
        user = User.objects.get(username=form_data['username'])
        self.assertEqual(user.username, form_data['username'])
        profile = user.get_profile()

        # Check presence of postal addresses
        self.assertEqual(profile.postal_address.city, self.f_valid_postal_address_form_data['city'])
        self.assertEqual(profile.delivery_address.city, self.f_valid_postal_address_form_data['city'])
        user.delete()