예제 #1
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(form.password.data).decode('UTF-8')
        new_user = User(username=form.username.data, email=form.email.data, password=hashed_pw)
        db.session.add(new_user)
        db.session.commit()
        flash('Your account has been created. Please Login ','success')
        return redirect(url_for('main.login'))
    return render_template('register.html', title='Register', form=form)
def register():
    form = RegistrationForm()
    if request.method == 'POST' and form.validate_on_submit():
        print('Form: ', form)
        user = User.query.filter_by(username=form.username.data).first()
        if user:
            return render_template('registration.html', form=form, message='The user already exists.', type='danger')
        user = User.register(form.username.data, form.password.data)
        message = 'The user "{}" was registered successfully.'.format(user.username)
    else:
        message = None
    return render_template('registration.html', form=form, message=message, type='success')
예제 #3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('main.login'))
    return render_template('register.html', title='Register', form=form)
예제 #4
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('main.login'))
    return render_template('register.html', title='Register', form=form)
예제 #5
0
파일: views.py 프로젝트: kayongopique/SBMS
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(email=form.email.data, username=form.username.data, name=form.name.data, \
            location=form.location.data, password=form.password.data,\
                  about_me=form.about_me.data)
        db.session.add(user)
        db.session.commit()        
        token = user.generate_token()        
        send_mail(user.email, 'Confirm Your Account', \
            'auth/email/confirm', user=user, token=token)        
        flash('A confirmation email has been sent to you by email.')
        return redirect(url_for('main.index'))
    return render_template('auth/register.html', form=form)
예제 #6
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        password_hash = generate_password_hash(form.password.data)
        user = User(username=form.username.data,
                    email=form.email.data,
                    password_hash=password_hash)
        #user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('main.login'))
    return render_template('register.html', title='Register', form=form)
예제 #7
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Account has been created! You are now able to login', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
def register():
    form = RegistrationForm(request.form)
    status = 200
    if request.method == 'POST' and form.validate():
        user = User(form.username.data, form.password.data)
        try:
            db.session.add(user)
            db.session.commit()
            flash('Thanks for registering')
            return redirect(url_for('main.login'))
        except sqlalchemy.exc.IntegrityError:
            db.session.rollback()
            flash('Username {} already taken'.format(form.username.data))
            status = 400

    return render_template('register.html', form=form), status
예제 #9
0
def register():
  if current_user.is_authenticated:
    return redirect(url_for('index'))
  form = RegistrationForm()
  user = User(username=form.username.data, email=form.email.data)
  user.set_password(form.password.data)
  db.session.add(user)
  db.session.commit()
  return 'You registered'
예제 #10
0
def process_registration():
    form = RegistrationForm()
    if form.validate_on_submit():
        try:
            user = admin_api_client.register(form.email_address.data,
                                             form.password.data,
                                             form.mobile_number.data)
            code = ''.join(["%s" % randint(0, 9) for num in range(0, 5)])
            session['code'] = hashpw(code)
            session['new_user_id'] = user['users']['id']
            admin_api_client.send_sms(form.mobile_number.data, code)
            return redirect(url_for('.view_3fa'))
        except APIError as e:
            print(e.response.json())
            flash("Error creating user", "error")
            return render_template('register.html',
                                   **get_template_data(form=form)), 400

    else:
        return render_template('register.html',
                               **get_template_data(form=form)), 400
예제 #11
0
def home():
    users = []
    form = RegistrationForm()
    if form.validate_on_submit():
        firstName = form.firstName.data.capitalize()
        lastName = form.lastName.data.capitalize()
        email = form.email.data.lower()
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode(
                'UTF-8')  # Encrypt the password stored in form.password.data
        user = User(FirstName=firstName,
                    LastName=lastName,
                    Email=email,
                    Password=hashed_password)
        db.session.add(user)
        db.session.commit()
        # Login the user with the session duration set
        login_user(user, duration=timedelta)
        # Second argument is optional, uses to assign what category the message is
        flash('Signed in!', 'success')
        return redirect(url_for('main.home'))
    if current_user.is_authenticated:
        posts = current_user.followed_posts().all()
        # users = User.query.filter(User.id != current_user.id).order_by(
        #     func.random()).limit(3).all()
        tempUsers = User.query.filter(User.id != current_user.id).order_by(
            func.random()).all()

        for tempUser in tempUsers:
            if not current_user.is_following(tempUser) and len(users) <= 2:
                users.append(tempUser)

        return render_template('user-index.html',
                               posts=posts,
                               users=users,
                               active='home')

    # posts = Post.query.order_by(Post.DatePosted.desc())
    return render_template('index.html', form=form)
예제 #12
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('main.home_page'))
    form_signup = RegistrationForm()
    if form_signup.validate_on_submit(
    ):  # this will tell us if the for was valid when
        # submitted
        user = User(username=form_signup.username.data,
                    first_name=form_signup.firstname.data,
                    last_name=form_signup.surname.data,
                    email=form_signup.email.data,
                    roles=form_signup.role.data)
        user.set_password(form_signup.password.data)
        # adding the role of the user- property_owner or renter

        db.session.add(user)
        db.session.commit()
        flash(
            'congratulations, you have created an account! Please log in to continue browsing!',
            'success')
        return redirect(url_for('main.login'))
    return render_template('signup.html', title='signup', form=form_signup)
예제 #13
0
def process_registration():
    form = RegistrationForm()
    if form.validate_on_submit():
        try:
            user = admin_api_client.register(form.email_address.data, form.password.data, form.mobile_number.data)
            code = ''.join(["%s" % randint(0, 9) for num in range(0, 5)])
            session['code'] = hashpw(code)
            session['new_user_id'] = user['users']['id']
            admin_api_client.send_sms(form.mobile_number.data, code)
            return redirect(url_for('.view_3fa'))
        except APIError as e:
            print(e.response.json())
            flash("Error creating user", "error")
            return render_template(
                'register.html',
                **get_template_data(form=form)
            ), 400

    else:
        return render_template(
            'register.html',
            **get_template_data(form=form)
        ), 400
예제 #14
0
def register():
    from app.main.forms import RegistrationForm
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(role='Student',
                    email=form.email.data,
                    username=form.username.data,
                    password=form.password.data,
                    idNumber=form.idNumber.data,
                    private=form.private.data,
                    firstName = form.firstName.data,
                    lastName = form.lastName.data,
                    classYear = form.classYear.data,
                    major = form.major.data,
                    numComplete = 0)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created. You may now login!')
        challengeList=[]
        for a in Challenge.query.order_by('id'):
            challengeList.append(a.name)
        return render_template('ictraditions.html', challengeList=challengeList)
    return render_template('register.html', form=form)
예제 #15
0
def registration():
    if g.user.is_authenticated():
        return redirect(url_for('main.personal'))

    form = RegistrationForm()
    if form.validate_on_submit():
        User.add_user(User(username=form.name.data,
                           password=form.password.data,
                           email=form.email.data,
                           confirmed=False))

        token = generate_confiramation_token(form.name.data)
        confirm_url = url_for("main.confirmation", token=token, _external=True)
        html_mail = render_template('user/activate.html', confirm_url=confirm_url)
        try:
            send_email(to=form.email.data, subject='registration on toDo', template=html_mail)
        except Exception as e:
            _log.error("E-mail was not sent")
            _log.error("Exception: %s" % str(str(e)))
        flash("Welcome! Please, follow link from confirmation email to finish registration.", 'info')

        return redirect(url_for('main.login'))
    return render_template('registration.html', form=form)
예제 #16
0
def admin_create_user():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate_on_submit():
        name = form.name.data
        email = form.email.data
        password = encrypt_password(form.password.data)
        user_exists = User.query.filter_by(email=email).first()
        if user_exists:
            form.email.errors.append(
                email + ' is already associated with another user')
            form.email.data = email
            email = ''
            return render_template('users/user_create.html', form=form)
        else:
            security = current_app.extensions.get('security')
            security.datastore.create_user(name=name,
                                           email=email,
                                           password=password,
                                           confirmed_at=datetime.now())
            db.session.commit()
            user = security.datastore.get_user(email)
            flash('User added successfully.')
            return redirect(url_for('main.show_users'))
    return render_template('users/user_create.html', form=form)
예제 #17
0
def register():

    evlist = event_list().evlist
    list = [(str(event["event_id"]), event["event_name"]) for event in evlist]
    set_evlist(list)
    session['evlist'] = evlist
    form = RegistrationForm()

    if form.validate_on_submit():
        if current_user.is_authenticated:
            user = current_user.username
        else:
            user = "******"
        salt = '8f1e39a21c9d4661b24a06356e5fe4d1'
        ORDER_ID = str(uuid.uuid4())
        CUST_ID = str(
            hashlib.md5(salt.encode() + form.phno.data.encode()).hexdigest())

        ev_selected = int(form.event.data)
        selectedEvent = next(
            (item for item in evlist if item["event_id"] == ev_selected), None)

        if (selectedEvent is None):
            flash("An error occured")
            return redirect(url_for('.register'))
        TXN_AMOUNT = int(selectedEvent["amt"])

        registration = registrations(name=form.name.data,
                                     phno=form.phno.data,
                                     email=form.email.data,
                                     clgname=form.clgname.data,
                                     grpname=form.GrpName.data,
                                     team=form.radio_team.data,
                                     event_id=ev_selected,
                                     user=user,
                                     order_id=ORDER_ID,
                                     cust_id=CUST_ID,
                                     amt=str(TXN_AMOUNT),
                                     paymentmode='ONLINE')
        registration_dict = vars(registration)
        registration_dict.pop('_sa_instance_state', None)
        session['reg_info'] = registration_dict
        registration = registrations(**registration_dict)

        try:
            if request.form.get('submit_ofc',
                                False) == "REGISTER ( Pay via Cash )":
                try:
                    registration.paid = True
                    registration.paymentmode = 'Cash'

                    db.session.add(registration)
                    db.session.commit()

                    flash('Registration Successful')
                    print('Offline Registration Done')
                    try:
                        # send_email(registration_dict,evlist)
                        flash(
                            'An Email consisting of Registration Details has been sent to the specified email address'
                        )
                    except Exception as error:
                        print(error)
                        traceback.print_exc()
                except Exception as error:
                    db.session.rollback()
                    flash('Registration Failed')
                    print(error)
                    traceback.print_exc()

                return redirect(
                    url_for('.success',
                            order_id=registration_dict['order_id'],
                            user_id=registration_dict['cust_id']))

            else:
                environment = os.getenv('FLASK_ENV')
                # initialize a dictionary
                paytmParams = dict()
                paytmParams["body"] = {
                    "requestType":
                    "Payment",
                    "mid":
                    app.config['MID'],
                    "websiteName":
                    app.config['WEBSITE']
                    if environment == "production" else "WEBSTAGING",
                    "orderId":
                    ORDER_ID,
                    "callbackUrl":
                    request.host_url + "payment",
                    "txnAmount": {
                        "value": str(TXN_AMOUNT),
                        "currency": "INR",
                    },
                    "userInfo": {
                        "custId": CUST_ID,
                        "mobile": str(form.phno.data),
                        "email": form.email.data,
                    },
                }

                # Generate checksum by parameters we have
                # Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys

                checksum = paytmchecksum.generateSignature(
                    json.dumps(paytmParams["body"]),
                    app.config['MERCHANT_KEY'])

                paytmParams["head"] = {
                    "signature": checksum,
                    "channelId": app.config['CHANNEL_ID']
                }

                postData = json.dumps(paytmParams)

                initiateTxnUrl = app.config["PAYMENT_URL" if environment == "production" else "PAYMENT_URL_STAGING"] + "initiateTransaction?mid=" + \
                    app.config["MID"] + "&orderId=" + ORDER_ID

                paytmResponse = requests.post(initiateTxnUrl,
                                              data=postData,
                                              headers={
                                                  "Content-type":
                                                  "application/json"
                                              }).json()

                paymentPageUrl = app.config["PAYMENT_URL" if environment == "production" else "PAYMENT_URL_STAGING"] + "showPaymentPage?mid=" + \
                    app.config["MID"] + "&orderId=" + ORDER_ID

                return render_template(
                    '/paymentform.html',
                    mid=paytmParams.get("body").get("mid"),
                    orderId=paytmParams.get("body").get("orderId"),
                    url=paymentPageUrl,
                    txnToken=paytmResponse.get("body").get("txnToken"))
        except Exception as error:
            print(error)
            traceback.print_exc()

    return render_template('/Main.HTML', form=form, evlist=evlist)
예제 #18
0
def render_registration_page():
    return render_template("register.html",
                           form=RegistrationForm(),
                           **get_template_data())
예제 #19
0
파일: routes.py 프로젝트: anoopkarnik/SNFE
def home(order='time'):
    users = []
    form = RegistrationForm()
    init_interests()
    print(len(Interest.query.all()))
    interests = Interest.query.all()

    if form.validate_on_submit():
        user_role = Role(name="user")
        db.session.add(user_role)
        db.session.commit()
        admin_role = Role(name="admin")
        db.session.add(admin_role)
        db.session.commit()
        firstName = form.firstName.data.capitalize()
        lastName = form.lastName.data.capitalize()
        email = form.email.data.lower()
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode(
                'UTF-8')  # Encrypt the password stored in form.password.data
        user = User(FirstName=firstName,
                    LastName=lastName,
                    Email=email,
                    Password=hashed_password,
                    roles=[user_role])
        db.session.add(user)
        db.session.commit()
        # user = db.session.query(User).get(current_user.id)

        # Login the user with the session duration set
        login_user(user, duration=timedelta)
        # Second argument is optional, uses to assign what category the message is
        flash('Signed in!', 'success')
        return redirect(url_for('main.home'))
    if current_user.is_authenticated:
        posts = Post.query.order_by(Post.DatePosted.desc()).all()
        # users = User.query.filter(User.id != current_user.id).order_by(
        #     func.random()).limit(3).all()
        tempUsers = User.query.filter(User.id != current_user.id).order_by(
            func.random()).all()
        likes = {}
        user_interests = current_user.UserInterests.all()
        print(user_interests)
        for i in range(len(posts)):
            likes[posts[i]] = len(posts[i].LikedUsers.all())
        for tempUser in tempUsers:
            if not current_user.is_following(tempUser) and len(users) <= 2:
                users.append(tempUser)
        if order == 'popularity':
            sorted_likes = sorted(likes.items(),
                                  key=lambda item: item[1],
                                  reverse=True)
            likes = {k: v for k, v in sorted_likes}
            return render_template('user-index.html',
                                   posts=likes,
                                   users=users,
                                   interests=interests,
                                   user_interests=user_interests,
                                   active='home',
                                   subactive='popularity')
        else:
            return render_template('user-index.html',
                                   posts=likes,
                                   users=users,
                                   interests=interests,
                                   user_interests=user_interests,
                                   active='home',
                                   subactive='time')

    # posts = Post.query.order_by(Post.DatePosted.desc())
    return render_template('register.html', form=form)