示例#1
0
def signup():
    try:
        form = SignupForm()
        if form.validate_on_submit():
          print "I am here"
          the_user = session.query(User).filter_by(mobilenumber = form.mobile.data).first()
          if the_user:
            flash("User with same mobile number already exist")
          else:
            user = User(name = form.name.data,
                   email = form.email.data,
                   password = generate_password_hash(form.password.data),
                   mobilenumber = form.mobile.data)
            session.add(user)
            session.commit()
            token = generate_confirmation_token(user.email)
            confirm_url = url_for('confirm_email',token = token,_external = True)
            html = render_template('activate.html',confirm_url = confirm_url)
            subject = "Please confirm your email {}.".format(user.name)
            send_email(user.email,subject,html)
            flash("Thank you for Registering {}.".format(user.name))
            flash("We have sent you a confirmation email to your registered email and its valid for 1 hour")
            flash("It may take 1 minute to arrive")
            flash("Please click on confirmation link sent in mail")
            return redirect(url_for('confirm'))

        return render_template('signup.html',form = form)
    except Exception as e:
        print e
def change_password():
    req = request.get_json()
    existing_user = Users.query.filter_by(email=req["email"]).first()
    if not existing_user:
        flash("Invalid email. Please try again.")
        return redirect(url_for("dashboard.login"))
    # create gmail client
    gmail = Gmail(delegated_user="******")
    # generate password token
    password_token = generate_confirmation_token(existing_user.email)

    # Fill in email body and send email
    email_body = """Please click on the link to reset your BarScreen password. Link: https://dashboard.barscreen.tv{}""".format(
        url_for('dashboard.confirm_email', token=password_token), )
    gmail.send_email(to=existing_user.email,
                     subject="BarScreen Account",
                     body=email_body)
    return jsonify({"success": True})
def approve_user():
    req = request.get_json()
    existing_user = Users.query.filter_by(email=req["email"]).first()
    if existing_user.confirmed:
        abort(400, "User is confirmed already.")

    # create gmail client
    gmail = Gmail(delegated_user="******")
    # generate password token
    password_token = generate_confirmation_token(existing_user.email)

    # Fill in email body and send email
    email_body = """Congratulations you have been approved for a Barscreen account! Below is a link to create a password. Your email will be used for your username. Link: {}""".format(
        url_for('dashboard.confirm_email', token=password_token),
    )
    gmail.send_email(to=existing_user.email,
                     subject="BarScreen Account", body=email_body)
    return jsonify({"success": True})
示例#4
0
def resend_confirmation():
  try:
      form = ResendForm()
      if form.validate_on_submit():
        user = session.query(User).filter_by(email = form.email.data).first()
        if user:
          token = generate_confirmation_token(form.email.data)
          confirm_url = url_for('confirm_email',token = token,_external = True)
          html = render_template('activate.html',confirm_url = confirm_url)
          subject = "Please confirm your email {}.".format(user.name)
          send_email(user.email,subject,html)
          flash("Confirmation link sent to your registered email\nPlease click on the link to confirm your email")
          return redirect(url_for('confirm'))
        else:
          flash("You are not registered.\nPlease Register")
          return render_template('unconfirmed.html')
      return render_template('resend.html',form = form)
  except Exception as e:
      print e
示例#5
0
def add_user():
    """Add new user"""
    form = UserForm()
    if form.validate_on_submit():
        try:
            user = User.signup(username=form.username.data,
                               password=form.password.data,
                               email=form.email.data)
        except IntegrityError:
            flash('Username already taken', 'danger')
            return render_template('/newuser', form=form)
        db.session.commit()
        token = generate_confirmation_token(user.email)
        confirm_url = url_for('confirm_email', token=token, _external=True)
        html = render_template('activate.html', confirm_url=confirm_url)
        subject = 'Please confirm your email'
        send_email(user.email, subject, html)
        return redirect("/unconfirmed")
    else:
        return render_template('newuser.html', form=form)