示例#1
0
def signup(request):
    if request.user.is_authenticated:
        return redirect('/home')

    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()

            current_site = get_current_site(request)
            mail_subject = 'Activate your blog account.'
            message = render_to_string(
                'app/acc_active_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()
            return render(request, 'app/user_confirmation.html')
    else:
        form = SignupForm()
    return render(request, 'app/user_registration.html', {'form': form})
示例#2
0
文件: htmlviews.py 项目: me2d09/prius
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()

            try:
                sendActivationMail(user, get_current_site(request))
            except:
                return render(
                    request, 'registration/message.html', {
                        'text':
                        'System was not able to send you email with activation link. '
                        + 'Please try again or contact support.',
                    })

            return render(
                request, 'registration/message.html', {
                    'text':
                    'Registration was successful and activation e-mail was send to you. '
                    +
                    'Please check your mailbox (and possibly spam folder) and activate your account.',
                })
    else:
        form = SignupForm()
    return render(request, 'registration/signup.html', {'form': form})
示例#3
0
def splash(request):
    signupform = SignupForm()
    authform = AuthForm()
    if request.method == 'POST':
        signupform = SignupForm(request.POST)
        if signupform.is_valid():
            if username_exists(signupform.cleaned_data["username"]):
                messages.error(request, 'Username already exists.')
                return render(request, 'splash.html', {
                    'signupform': signupform,
                    'authform': authform
                })
            if email_exists(signupform.cleaned_data["email"]):
                messages.error(request,
                               'User already exists with this email address.')
                return render(request, 'splash.html', {
                    'signupform': signupform,
                    'authform': authform
                })

            user = User.objects.create_user(
                signupform.cleaned_data["username"],
                signupform.cleaned_data["email"],
                signupform.cleaned_data["password"])
            user.first_name = signupform.cleaned_data["first_name"]
            user.last_name = signupform.cleaned_data["last_name"]
            user.save
            return render(request, 'dashboard.html')
    else:
        signupform = SignupForm()
    return render(request, 'splash.html', {
        'signupform': signupform,
        'authform': authform
    })
示例#4
0
def signup(request):
    if request.method == 'GET':
        form = SignupForm()
    else:
        form = SignupForm(data=request.POST)
        if form.is_valid():
            username_ = form.cleaned_data.get('login')
            email = form.cleaned_data.get('email')
            password1 = form.cleaned_data.get('password1')
            user_ = User.objects.create_user(username_, email, password1)
            Author.objects.create(user=user_, user_name=username_)
            auth.login(request, user_)
            return redirect('/')
    return render(request, 'signup.html', {'form': form})
示例#5
0
def signup_login():
  if current_user.is_authenticated: #do not show the signup/login page to users who are already logged in
    return redirect(url_for('index'))
  form1 = SignupForm()
  form2 = LoginForm()

  #if user submits signup form
  if form1.submitSignup.data and form1.validate_on_submit():
    user = User(username=form1.username.data, email=form1.email.data)
    user.set_password(form1.password.data) #store hash of user's password
    db.session.add(user)
    db.session.commit()
    flash('Thanks for signing up, you can now log in')
    return redirect(url_for('signup_login'))
  
  #if user submits login form
  if form2.submitLogin.data and form2.validate_on_submit():
    user = User.query.filter_by(username=form2.username.data).first()

    #if provided username doesnt exist or incorrect password
    if user is None or not user.check_password(form2.password.data):
      flash('Invalid username or password')
      return redirect(url_for('signup_login'))
    
    #else login successful
    login_user(user) #store the logged in user in current_user
    next_page = request.args.get('next') #send user to their intended page, if they were redirected due to not logged in
    if not next_page or url_parse(next_page).netloc != '':
      next_page = url_for('index')
    return redirect(next_page) #return user to whatever page they were visiting, but now logged in
  return render_template('signuplogin_page.html', signForm=form1, logForm=form2)
示例#6
0
def main():
    return render_template('main.html',
                           login=LoginForm(),
                           signup=SignupForm(),
                           movie=SelectMovieForm(),
                           question=QuestionForm(),
                           answer=AnswerForm())
示例#7
0
文件: auth.py 项目: codeOlam/socimo
def signup():
    """
    User sign-up page.

    GET requests serve sign-up page.
    POST requests validate form & user creation.
    """
    if current_user.is_authenticated:
        print('Checking if current user is_authenticated')
        print('current_user :'******'newsfeed'))

    form = SignupForm()
    # if request.method == 'POST':
    #     #This is to help store files in b'' and save directly to db
    #     pic = request.files['photo'].read()

    if form.validate_on_submit():
        print('validating...')
        user = User(name=form.name.data, email=form.email.data)  #, photo=pic
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Account Succefully Created!')
        login_user(user)
        return redirect(url_for('newsfeed'))
    return render_template('sign-up.html',
                           title='Create an Account.',
                           form=form)
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        if User.query.filter_by(email=request.form['email']).first():
            flash('This email is already in use')
        elif User.query.filter_by(username=request.form['username']).first():
            flash('This username is already taken')
        elif len(str(request.form['password'])) < 8:
            flash('Password is too short')
        else:
            highscore = Highscore(0, 0, 0, 0, 0, 0, 1000, 0, 0, 0, 0, 0)
            user = User(username=request.form['username'],
                        email=request.form['email'],
                        plaintext_password=request.form['password'])
            highscore.users.append(user)
            db.session.add(highscore)
            db.session.commit()
            session['logged_in'] = True
            session['username'] = user.username
            session['deathalltime'] = highscore.deathalltime
            session['deathlastmonth'] = highscore.deathlastmonth
            session['deathlastweek'] = highscore.deathlastweek
            session['gamesalltime'] = highscore.gamesalltime
            session['gameslastmonth'] = highscore.gameslastmonth
            session['gameslastweek'] = highscore.gameslastweek
            session['rating'] = highscore.raiting
            session['ratingmonth'] = highscore.raitingmonth
            session['ratingweek'] = highscore.raitingweek
            session['winsalltime'] = highscore.winsalltime
            session['winslastmonth'] = highscore.winslastmonth
            session['winslastweek'] = highscore.winslastweek
            highscores = Highscore.query.all()
            set_positions(highscores, highscore)
            return redirect('/')
    return render_template('signup.html', form=form)
示例#9
0
def profile():
    myform = SignupForm()
    if request.method == "POST":
        if myform.validate_on_submit():
            first = myform.firstname.data
            last = myform.lastname.data
            gen = myform.gender.data
            email = myform.email.data
            loc = myform.location.data
            bio = myform.biography.data
            pic = request.files['file']
            now = datetime.now()
            signdate = now.strftime("%B") + " " + str(now.day) + ", " + str(
                now.year)
            photoname = secure_filename(pic.filename)
            pic.save(os.path.join(app.config['UPLOAD_FOLDER'], photoname))

            user = UserProfile(first, last, gen, email, loc, bio, signdate,
                               photoname)
            db.session.add(user)
            db.session.commit()

            flash("Profile Successfully Created", "success")
            return redirect("/")
        else:
            flash("Failed to create profile", "danger")
    return render_template('profile.html', myform=myform)
示例#10
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():
            # find user in database
            user=User.query.filter_by(email=form.email.data).first()
            if user:
                # hash password
                password = form.password.data
                # verify password against hash
                if sha256_crypt.verify(password, user.password):

                    # log user into app session
                    login_user(user)

                    return redirect(url_for('index'))

                # if password does not match hash
                else:
                    error = "Wrong password"
                    return render_template('login.html', form=form, error=error)
            # user does not exist in database
            else:
                error = "User doesn't exist. Please sign up"
                return render_template('login.html', form=form, error=error)
        # if form doesn't validate
        else:
            error = "Form didn't validate"
            return render_template('login.html', form=form, error=error)
示例#11
0
def register():
    form = SignupForm()

    if request.method == 'GET':
        return render_template('signup.html', form=form)

    elif request.method == 'POST':
        if form.validate_on_submit():

            # search if email already exists
            if User.query.filter_by(email=form.email.data).first():
                error = "Email address already exists"
                return render_template('signup.html', form=form, error=error)

            # create user if user does not exist in database
            else:
                password = form.password.data
                # safely store hashed password
                hash_password = sha256_crypt.hash(password)
                newuser = User(form.email.data, hash_password)
                db.session.add(newuser)
                db.session.commit()

                flash('Thanks for registering!')
                return redirect(url_for('login'))

        # if form doesn't validate
        else:
            error = "Form didn't validate"
            return render_template('signup.html', form=form, error=error)
示例#12
0
def signup():
    # # Disable access to login page if user is already logged in.
    if current_user.is_authenticated:
        flash("You are already signed up!")
        return redirect(url_for('index'))
    form = SignupForm(
    )  # created an instance of SignupForm() and called it "form"
    # Check if email was used for another account

    # Checks if form fields are filled
    # if it is, create a new user with provided credentials
    if request.method == 'POST':
        if form.validate_on_submit():

            if User.query.filter_by(email=form.email.data).first():
                flash("This email is already in use")
                return redirect(url_for('users.signup'))

            new_user = User(first_name=form.first_name.data,
                            last_name=form.last_name.data,
                            email=form.email.data,
                            password=form.password.data,
                            wca_id=None,
                            dob=None)
            new_user.credentials = 1

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

            flash("You have successfully signed up! Please log in!")
            return redirect(url_for('index'))
        else:
            return render_template('signup.html', form=form)

    return render_template('signup.html', form=form)
示例#13
0
def signup():
    signup_form = SignupForm()

    if signup_form.validate_on_submit():
        email = signup_form.email.data
        password = signup_form.password.data

        user_doc = get_user(email).to_dict()
        if user_doc is None:
            password_hash = generate_password_hash(password)
            user_data = UserData(email, password_hash)

            user_put(user_data)

            user = UserModel(user_data)
            login_user(user)

            flash('Welcome to our app', 'success')

            return redirect(url_for('panel'))
        else:
            signup_form.email.errors.append('User already exists')

    context = {
        'signup_form': signup_form,
    }

    return render_template('signup.html', **context)
示例#14
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('user.meal_plan'))

    form = SignupForm()
    if request.method == "POST" and form.validate_on_submit():
        fname = form.fname.data
        lname = form.lname.data
        email = form.email.data
        password = form.password.data
        rpassword = form.rpassword.data

        if password == rpassword:

            result = populate_database.insertUser({'fname':fname, 'lname':lname,\
                                                'email':email,'password':password})
            if result == True:
                # flash a message to the user
                flash('Sign up successful.', 'success')
                return redirect(url_for("user.login"))
            elif result == False:
                flash('Email address is already associated with an account',
                      'danger')
            else:
                flash('Database connection error', 'danger')
        else:
            flash('Passwords does not match', 'danger')
    return render_template("sign_up.html", form=form)
def admin_page():
    if current_user.admin:
        form = SignupForm()
        return render_template('admin_page.html', logo=logo, form=form)
    else:
        logout_user()
        return redirect(url_for('login'))
def signup():
    print('signup')
    form2 = SignupForm()
    form = LoginForm()
    error = ''

    if request.method == 'POST':
        print(form2.validate())
        if form2.submit.data and form2.validate_on_submit():
            name = form2.username.data
            emailid = form2.emailid.data
            password = form2.password.data

            # password = password.encode('utf-8')
            import hashlib, uuid
            salt = uuid.uuid4().hex
            # salt = salt.encode('utf-8')
            hashed_password = hashlib.sha256((salt+password ).encode('utf-8')).hexdigest()

            print(name,emailid,hashed_password)
            if(name and emailid and hashed_password):
                error = createNewUser(name,emailid,hashed_password,salt)
                # name=name
            else:
                error = "Don't have sufficient field data!"
    return render_template('index.html', form2=form2 , form=form, error = error)
示例#17
0
def signup():
    sign = SignupForm()
    if request.method == 'GET':
        return render_template('signup.html', form=sign)

    elif request.method == 'POST':
        firstname = sign.firstname.data
        lastname = sign.lastname.data
        username = sign.username.data
        password = sign.password.data
        email = sign.email.data
        gender = sign.gender.data
        phonenumber = sign.phonenumber.data

        user_Signup = SignUp(Firstname=firstname,
                             Lastname=lastname,
                             Username=username,
                             Password=password,
                             Email=email,
                             Gender=gender,
                             Phonenumber=phonenumber)
        # adding user_insert to signup table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        db.session.add(user_Signup)
        db.session.add(user_Signup)

        user_Login = Login(Username=username, Password=password)
        #adding to login table
        db.session.add(user_Login)
        db.session.commit()

        #messageSuccess = "You have successfully signed up"
        return render_template('index.html')

    else:
        messageFail = "Wrong request"
        return messageFail
示例#18
0
def signup():
    form = SignupForm()

    context = {
        'form': form
    }

    if request.method == 'POST':
        username = form.username.data
        password = form.password.data
        password2 = form.password2.data

        if form.check_password(password, password2):
            user_doc = get_user(username)
            
            if user_doc.to_dict() is None:
                user_data = UserData(
                    username=username,
                    password=generate_password_hash(password)
                )

                user_put(user_data)

                user = UserModel(user_data)
                return redirect(url_for('auth.login'))
            else:
                flash('User already exists.')
        else:
            flash('Passwords didn\' match.')

    return render_template('signup.html', **context)
示例#19
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        flash('Signup requested for user {}, remember_me={}'.format(
            form.full_name.data, form.email.data))
        return redirect('/profile')
    return render_template('signup.html', title='Signup', form=form)
示例#20
0
def signup():

    search = SearchForm()
    if request.method == 'POST' and search.validate_on_submit():
        return redirect((url_for('search_page',
                                 searchQuery=search.searchParam.data)))

    if session.get('logged_in') == True:
        return redirect(url_for('index'))

    form = SignupForm()
    if form.validate_on_submit():
        name = form.restaurant_name.data
        email = form.restaurant_email.data
        phone = form.restaurant_phone.data
        zipcode = form.restaurant_zipcode.data
        address = form.restaurant_street.data + form.restaurant_city.data + form.restaurant_state.data
        new_seller = seller(seller_name=name,
                            seller_email=email,
                            seller_phone=phone,
                            seller_zipcode=zipcode,
                            seller_address=address)
        new_seller.set_password(form.restaurant_password.data)
        db.session.add(new_seller)
        db.session.commit()
        session["user_id"] = new_seller.seller_id
        session["logged_in"] = True
        return redirect(url_for('index'))

    return render_template('signup.html',
                           title='Sign Up',
                           form=form,
                           search=search)
示例#21
0
def signup():
    signup_form = SignupForm()

    context = {"signup_form": signup_form}

    if signup_form.validate_on_submit():
        username = signup_form.username.data
        email = signup_form.email.data
        password = signup_form.password.data

        user_doc = get_user(email)

        if user_doc.to_dict() is None:
            password_hash = generate_password_hash(password)
            user_data = UserData(username, email, password_hash)
            user_put(user_data)

            user = UserModel(user_data)

            login_user(user)

            flash("Bienvenido")

            return redirect(url_for("hello"))

        else:
            flash("El usuario ya existe")

    return render_template("signup.html", **context)
示例#22
0
def signup():
    form = SignupForm()
    if "email" in session:
        return redirect(url_for('profile'))

    if request.method == 'POST' and 'name' in request.form and 'password' in request.form and 'email' in request.form:
        name = request.form['name']
        password = request.form['password']
        email = request.form['email']
        cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
        cursor.execute('SELECT * FROM USERS WHERE email = %s', (email, ))
        account = cursor.fetchone()
        if account:
            flash('Email already Exists!')
        else:
            fid = random.randint(1, 9999)
            cursor.execute(
                '''INSERT INTO USERS VALUES (%s, %s, %s,%s,'1234567890',-1,-1,-1,'NA')''',
                (name, email, password, fid))
            cursor.execute(
                '''INSERT INTO DETAILS VALUES (%s, %s,'NA',-1,%s,'1234567890',-1,-1,-1,'NA','NA','NA')''',
                (name, email, fid))
            mysql.connection.commit()
            session["email"] = email
            flash('You have succesfully registered!')
            return redirect(url_for('profile'))
    elif request.method == 'POST':
        flash('Please fill out the form!')
    return render_template('signup.html', form=form, title="Signup")
示例#23
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    loginform = LoginForm()
    signupform = SignupForm()
    if request.method == 'GET':
        return render_template('login.html',
                               title='Sign In',
                               loginform=loginform,
                               signupform=signupform)
    elif request.method == 'POST':
        if loginform.validate_on_submit():
            print("LoginForm")
            user = User.query.filter_by(email=loginform.email.data).first()
            print(user)
            if user is None or not user.check_password(
                    loginform.password.data):
                flash('Invalid username or password')
                print("Invalid password")
                return redirect(url_for('login'))
            login_user(user, remember=loginform.remember_me.data)
            return redirect(url_for('index'))
        else:
            return render_template('login.html',
                                   title='Sign In',
                                   loginform=loginform,
                                   signupform=signupform)
示例#24
0
文件: views.py 项目: ec14240/new
def signup_user(request):
    if request.user.is_authenticated:
        # redirect to shop
        return redirect('/shop/fruit/')
    else:
        error = None
        if request.method == 'POST':
            form = SignupForm(request.POST)
            if form.is_valid():
                email = form.cleaned_data['email']
                first_name = form.cleaned_data['first_name']
                last_name = form.cleaned_data['last_name']
                phone = form.cleaned_data['phone']
                password = form.cleaned_data['password']
                password_confirm = form.cleaned_data['password_confirm']
                if not User.objects.filter(email=email).exists():
                    if password == password_confirm:
                        # create user
                        user = User.objects.create_user(email=email,
                                                        first_name=first_name,
                                                        last_name=last_name,
                                                        phone=phone,
                                                        password=password)
                        house = form.cleaned_data['house']
                        line1 = form.cleaned_data['line1']
                        postcode = form.cleaned_data['postcode']
                        # create associated address
                        Address.objects.create(house=house,
                                               line1=line1,
                                               postcode=postcode,
                                               user=user)
                        # create associated basket
                        Basket.objects.create(user=user)
                        # redirect to shop
                        login(request, user)
                        return redirect('/shop/fruit/')
                    else:
                        error = 'Passwords do not match.'
                else:
                    error = 'Email address is already in use.'
            else:
                error = 'Form details are invalid.'
        else:
            form = SignupForm()
        context = {'form': form, 'error': error, 'logged_in': False}
        return render(request, 'app/signup.html', context)
示例#25
0
文件: routes.py 项目: geer26/blancer
def index():

    loginform = LoginForm()
    signupform = SignupForm()

    if request.method == 'POST' and not current_user.is_authenticated:

        if loginform.validate_on_submit():
            user = User.query.filter_by(
                username=loginform.username.data).first()

            if not user or not user.check_password(loginform.password.data):
                mess = {}
                mess['event'] = 191
                mess['htm'] = render_template(
                    'errormessage.html',
                    message='Incorrect password or username')
                socket.emit('newmessage', mess)

            elif user and user.check_password(loginform.password.data):
                login_user(user, remember=loginform.remember_me.data)

                if user.pw_reset_token or user.pwrt_valid or user.pwrt_vcode != 0:
                    user.pw_reset_token = ''
                    user.pwrt_valid = None
                    user.pwrt_vcode = 0
                    user.pwrt_try = 0

                user.last_activity = datetime.now()
                db.session.commit()
                return redirect('/')

    if current_user.is_authenticated and current_user.is_superuser:

        users = User.query.order_by(User.id).all()
        pockets = Pocket.query.order_by(Pocket.user_id).all()
        transfers = Transfer.query.order_by(Transfer.timestamp).all()
        categories = Category.query.order_by(Category.user_id).all()

        return render_template('index.html', title='SU index', loginform=loginform, signupform=signupform,\
                               users=users, pockets=pockets, transfers=transfers, categories=categories)

    elif current_user.is_authenticated and not current_user.is_superuser:

        pockets = Pocket.query.filter_by(_user=current_user).all()

        ptransfers = get_ptransfers(current_user, 5)
        ntransfers = get_ntransfers(current_user, 5)

        return render_template('index.html', title='Index', loginform=loginform, signupform=signupform, pockets=pockets,\
                               ptransfers=ptransfers, ntransfers=ntransfers)

    else:

        return render_template('index.html',
                               title='Index',
                               loginform=loginform,
                               signupform=signupform)
示例#26
0
def signup(request):
    tags = Tag.objects.count_popular()
    if request.user.is_authenticated():
        return HttpResponseRedirect('/')
    form = SignupForm(request.POST, request.FILES)
    if request.method == "POST":

        if form.is_valid():
            user = form.save()
            auth.login(request, user)
            return HttpResponseRedirect('/')
    else:
        form = SignupForm()

    return render(request, 'register.html', {
        'form': form,
        'tags': tags,
    })
示例#27
0
def signup_post():
    signupForm = SignupForm()

    if signupForm.validate():
        #Verify that the user doesn't exist in the DB
        user = User.query.filter_by(email=signupForm.email.data).first()

        if user:
            flash('El email ya se encuentra registrado.')
            return redirect(url_for('auth.signup'))

        user = User.query.filter_by(username=signupForm.username.data).first()

        if user:
            flash('El usuario ya se encuentra registrado.')
            return redirect(url_for('auth.signup'))

        totalAmount = 0

        #Create the object User to store it in the DB
        new_user = User(email=signupForm.email.data,
                        username=signupForm.username.data,
                        password=generate_password_hash(
                            signupForm.password.data, method='sha256'))

        #Save both records in the DB
        db.session.add(new_user)
        db.session.commit()

        #Create the object UserConfiguration to store it in the BD
        new_user_config = UserConfiguration(spend_limit=totalAmount,
                                            warning_percent=75,
                                            hide_amounts=0,
                                            user_id=new_user.id)

        db.session.add(new_user_config)
        db.session.commit()

        #Create the object Saving to store it in the DB, by default is ARS (Pesos) with amount 0
        new_user_default_saving = Saving(user_id=new_user.id,
                                         currency_id=1,
                                         amount=0)

        db.session.add(new_user_default_saving)
        db.session.commit()

        #Send Slack Message notifying the new registration
        try:
            wsChannel = 'CSWSV4LLF'  #walletsentinel channel
            sendNewUserSlackMessage(wsChannel, signupForm.username.data)
        except:
            print('Ha ocurrido un error al enviar la notifiación a slack..')

        return redirect(url_for('auth.login'))
    else:
        return render_template('signup.html', form=signupForm)
示例#28
0
def signup():
    form = SignupForm()
    # vaildate signup form
    if form.validate_on_submit():
        # display sucessful sign up message
        flash('{} has signed up using email {} and password {}'.format(
            form.username.data, form.email.data, form.password.data))
        return redirect(url_for('index'))

    return render_template('signup.html', title='Sign Up', form=form)
示例#29
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        user = models.User(username=form.username.data,
                           password=form.password.data)
        db.session.add(user)
        db.session.commit()

        return redirect(url_for('index'))
    return render_template('signup.html', title='Sign Up', form=form)
示例#30
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        user = User(email= form.email.data,
                    username= form.username.data,
                    password = form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Welcome, {}!'.format(user.username))
        return redirect(url_for('login'))
    return render_template("signup.html", form=form)