Ejemplo n.º 1
0
def reg_user():
    form = RegForm()
    name = None
    email = None
    password = None

    if form.validate_on_submit():
        name = form.name.data
        email = form.email.data
        password = form.password.data
        email_con = email
        email_exists = Users.query.filter_by(user_email=email).first()
        if email_exists:
            flash(u'Email already exist, please login into your account',
                  'error')
            return redirect(url_for('auth.reg_user'))

        else:
            # the function below creates new user records in database
            Users.create_user(name, email, password)
            flash(
                'Registration Successful, an email confirmation link has been sent to your email',
                category='success')

            # this part send emil verfication link
            token = s.dumps(email_con, salt='email_verify')
            msg = Message('Confirm Email',
                          sender='*****@*****.**',
                          recipients=[email_con])
            link = url_for('auth.verify_email', token=token, _external=True)
            msg.body = 'Your link is {}'.format(link)
            mail.send(msg)
            return redirect(url_for('auth.home'))

    return render_template('reg.html', form=form)
Ejemplo n.º 2
0
def email_log(message):
    msg = Message("%s Notice Fitboard" % (message), recipients=["*****@*****.**"])
    msg.body = "NOTICE %s \n Logile Attached \n" % (message)
    with app.open_resource("fitboard.log") as fp:
        msg.attach("fitboard.log", "text/plain", fp.read())
    mail.send(msg)
    return
Ejemplo n.º 3
0
def register():
    title = 'Kekambas Blog | REGISTER'
    form = UserInfoForm()
    if request.method == 'POST' and form.validate():
        username= form.username.data
        email= form.email.data
        password= form.password.data
        # print(username, email, password)
        # create a new instance of User
        new_user= User(username, email, password)
        # add new instance of our database
        db.session.add(new_user)
        # commit database
        db.session.commit()
        # Send email to new user
        msg= Message(f'Welcome, {username}', [email])
        msg.body = 'Thank you for signing up for the Kekembas blog. I hope you enjoy our app!'
        msg.html = '<p> Thank you so much for signing up for the Kekemnbas blog. I hope you enjoy our app </p>'
        # send email

        mail.send(msg)

        flash('Welcome aboard!', 'success')
        return redirect(url_for("hello_world"))
    return render_template('register.html', title = title, form=form)
Ejemplo n.º 4
0
def register():
    title = 'Kekembas blog | REGISTER'
    form = UserInfoForm()
    

    if request.method == 'POST' and form.validate():
        username = form.username.data
        email = form.email.data
        password = form.password.data

        print(username,email, password)
        
        #create a new instance of User
        new_user = User(username,email,password)
        #add new instance of use
        db.session.add(new_user)
        #commit database
        db.session.commit()

        #SEND EMAIL TO NEW USER
        msg = Message(f"welcome, {username}", [email])
        msg.body = 'Thank you for siging up for the kekembas blog. I hope you enjoy our blog!'
        msg.html = '<p>Thank you so much for signing up for out blog!</p>'
        
        mail.send(msg)

        flash("You have succesfully signed up!", "success")
        return redirect(url_for('index'))

    return render_template('register.html', title=title,form=form)
Ejemplo n.º 5
0
def register():
    form = UserInfoForm()
    context = {'form': form}
    if request.method == 'POST' and form.validate():

        # Get Information
        username = form.username.data
        email = form.email.data
        password = form.password.data

        print(username, email, password)

        # Create new instance of User
        new_user = User(username, email, password)

        # Add user to db
        db.session.add(new_user)
        db.session.commit()

        # flash success message
        flash("You have successfully registered", 'success')

        # Flask Email Sender
        msg = Message(f'Thanks for signing up, {username}!',
                      recipients=[email])
        msg.body = ('Congrats on signing up! I hope you enjoy our site!!')
        msg.html = ('<h1>Welcome to Our Site</h1>'
                    '<p>This will be super cool!</p>')

        mail.send(msg)

        return redirect(url_for('index'))
    return render_template('register.html', **context)
Ejemplo n.º 6
0
def register():
    form = RegistrationForm()

    if request.method == 'POST':
        if form.validate() is False:
            flash("All fields are required for registration.")
            return render_template('register.html', form=form)
        else:
            newuser = User(form.username.data,
                           form.email.data, form.passwd.data)
            db.session.add(newuser)
            db.session.commit()

            # obtuser = User.query.filter_by(email=form.email.data.lower()).first()
            email = newuser.email.encode('ascii', 'ignore')
            reg_key = newuser.reg_key.encode('ascii', 'ignore')
            subject = "Your confirmation email from microBLOG"
            mail_to_be_sent = Message(subject=subject, recipients=[newuser.email])
            conf_url = url_for('confirm', reg_key=reg_key, _external=True)
            mail_to_be_sent.body = "Please click the link to confirm registration at microBLOG: %s" % conf_url
            mail.send(mail_to_be_sent)
            flash('Please check your email to confirm registration.  Then you can start using the site.')
            # session['email'] = newuser.email
            return redirect(url_for('homepage'))

    elif request.method == 'GET':
        return render_template('register.html', form=form)
Ejemplo n.º 7
0
def register():
    title = ddb + "register"
    form = UserInfoForm()
    if request.method == 'POST' and form.validate():
        username = form.username.data
        email = form.email.data
        password = form.password.data
        phone = form.phone.data
        address = form.address.data
        city = form.city.data
        zipcode = form.zipcode.data
        # admin = form.admin.data
        # print(username, email, password)

        # create new instance of User
        new_user = User(username, email, password,phone, address, city, zipcode)
        # add new instance to our database
        db.session.add(new_user)
        # commit database
        db.session.commit()

        # send email to new user
        msg = Message(f"Welcome, {username}", [email])
        msg.body = 'Thank you for signing up for the most glorious death of your bugs. I hope you enjoy your new carnage!'
        msg.html = "<p>Thanks you so much for signing up for the Dale's Dead Bugs service. Where we do buggin right! We may, or may not, be in Liberia!</p>"

        mail.send(msg) 

        flash("It may be a crack in your internet, or the Chinese are making their move!", "success")
        return redirect(url_for('index'))
    return render_template('register.html', title=title, form=form)
Ejemplo n.º 8
0
def register():
    title = "Virtual Tour Mates | REGISTER"
    form = UserInfoForm()
    if request.method == 'POST' and form.validate():
        username = form.username.data
        email = form.email.data
        password = form.password.data
        # print(username, email, password)
        
        # create a new instance of User
        new_user = User(username, email, password)
        # add new instance to our database
        db.session.add(new_user)
        # commit database
        db.session.commit()

        # Send email to new user
        msg = Message(f'Welcome, {username}', [email])
        msg.body = "Thank you for signing up for the Virtual Tour Mates. I hope you enjoy our app!"
        msg.html = "<p>Thank you so much for signing up for the Virtual Tour Mates. I hope you enjoy our app!</p>"

        mail.send(msg)

        flash("You have succesfully signed up!", "success")
        return redirect(url_for('index'))
    return render_template('register.html', title=title, form=form)
Ejemplo n.º 9
0
def userregister():
    if request.method == 'POST':
        session = DBSession()
        email = request.form['useremail']
        username = request.form['username']
        password = request.form['userpassword']
        password = generate_password_hash(password)
        print(email)
        if session.query(User).filter(User.email == email).first():
            return render_template('register.html', msg='该邮箱已被注册!')
        else:
            adduser = User(password=password, username=username, email=email, admin=0,activated=0)
            session.add(adduser)
            session.commit()
            os.makedirs(os.path.join(os.getcwd(),'static','files','{0}'.format(adduser.userid)))
            url='http://47.94.138.25/activate/{0}'.format(gen_token(adduser.userid))
            # message=Message('Account authorize',sender='*****@*****.**',recipients=['{}'.format(username),'{}'.format(email)])
            message = Message('Account authorize', sender='*****@*****.**',recipients=['*****@*****.**'])
            message.body="Hello,{0}<br>This email is from admin!<br>Your account has not been activated yet!<br><a href='{1}'>click here to activate your account!</a><br>if you mistaken the email,please ignore it!".format(username,url)
            mail.send(message)
            session.close()

            return redirect(url_for('users.userlogin'))
    else:
        return render_template('register.html')
Ejemplo n.º 10
0
def register():
    title = 'Kekembas Blog | REGISTER'
    form = UserInfoForm()
    if request.method == 'POST' and form.validate():
        username = form.username.data
        email = form.email.data
        password = form.password.data
        print(username, email, password)

        #create a new instance of user
        new_user = User(username, email, password)
        #add new instance to database
        db.session.add(new_user)
        #commit database
        db.session.commit()

        #send email to new user
        msg = Message(f'Welcome, {username}', [email])
        msg.body = 'Thank you for signing up to the Kekembas Blog, I hope you enjoy our app!'
        msg.html = '<p> Thank you so much for signing up for the Kekembas blog . I hopt you enjoy our app!</p>'

        mail.send(msg)

        flash("You have succesfully sign up!", "success")
        return redirect(url_for('hello_world'))

    return render_template('register.html', title=title, form=form)
Ejemplo n.º 11
0
def student_registration():

    if request.method == "POST":

        first_name = request.form['first_name']
        last_name = request.form['last_name']
        student_id = random.randrange(100000, 999999)
        student_email = request.form['student_email']
        parent_email = request.form['parent_email']
        student_phone_number = request.form['student_phone_number']
        parent_phone_number = request.form['parent_phone_number']
        city = request.form['city']
        standard = request.form['standard']
        current_address = request.form['current_address']
        board = request.form['board']

        subj = request.form.getlist('sub')
        #print(subj)

        subjects = ','.join(subj)

        auto_password = random.randrange(100000, 999999)

        string_pass = str(auto_password)

        hashed_password = bcrypt.generate_password_hash(string_pass).decode(
            'utf-8')

        student_password = hashed_password

        user = Students_data(student_id, first_name, last_name, student_email,
                             parent_email, student_phone_number,
                             parent_phone_number, city, standard,
                             current_address, board, subjects,
                             student_password)
        db.session.add(user)
        db.session.commit()

        ### Confirmation mail code  ###
        '''
        token = t.dumps(student_email, salt='email-confirm')
        msg = Message('Confirmation email', sender='*****@*****.**', recipients=[student_email])
        link = url_for('confirm_email', token=token, _external=True )
        msg.body = 'Your link is {}'.format(link)
        mail.send(msg)
        '''

        msg = Message(subject='Login details...',
                      recipients=[student_email, parent_email])
        msg.body = "Hello {} {}, Your login details are >> Student ID = {}, Password = {}".format(
            first_name, last_name, student_id, auto_password)
        mail.send(msg)

        msg = flash(
            'Registration successful ! Login details are on your mail.',
            'success')
        return render_template('student_login.html', msg=msg, subj=subj)

    return render_template('student_registration.html')
Ejemplo n.º 12
0
def message():
    formName = request.form['name']
    formEmail = request.form['email']
    formMessage = request.form['message']
    msg = Message('Hello, this is ' + formName + ' from ' + formEmail, sender=formEmail, recipients=['*****@*****.**'])
    msg.body = formMessage
    mail.send(msg)
    return 'success'
Ejemplo n.º 13
0
def email_log(message):
    msg = Message("%s Notice Fitboard" % (message),
                  recipients=["*****@*****.**"])
    msg.body = "NOTICE %s \n Logile Attached \n" % (message)
    with app.open_resource("fitboard.log") as fp:
        msg.attach("fitboard.log", "text/plain", fp.read())
    mail.send(msg)
    return
Ejemplo n.º 14
0
def send_async_email(recipients, link):
    """Background task to send an email with Flask-Mail."""
    subject = "Confirmation email for trololo.info"
    sender = '*****@*****.**'
    msg = Message(subject, sender=sender, recipients=recipients)
    msg.body = 'You can activate your account here: %s' % link
    with app.app_context():
        mail.send(msg)
Ejemplo n.º 15
0
def send_email(eml):
    """发送邮件"""
    message = Message('修改密码', recipients=[eml])
    code = ''.join(sample(ascii_letters + digits, 6))
    message.body = '【51商城】验证码:{}\t{}\n{}'.format(code, '此次验证码有效期为5分钟',
                                                 '如果非本人操作,请忽略!')
    mail.send(message)
    # TODO 应该存入redis 然后设置过期时间为3分钟
    session['code'] = code
Ejemplo n.º 16
0
def contact():
    form = ContactForm()
    if request.method == 'GET':
        return render_template('contact.html', form=form)
    else:
        if form.validate() == False:
            # errors are automatically stored in the form and template has access to them
            flash_errors(form)
            return render_template('contact.html', form=form)
        else:
            msg = Message("message from petri",
                          sender=form.email.data,
                          recipients=['*****@*****.**', '*****@*****.**'])
            msg.body = """From: %s %s <%s> %s""" % (form.firstname.data, form.lastname.data, form.email.data, form.message.data)
            mail.send(msg)
            flash('Your message been successfully sent')
            return render_template('contact.html', form=form)
Ejemplo n.º 17
0
def register():
    form = SignupForm()
    if request.method == 'POST':
        if form.validate() == False:
            return render_template('register.html', form=form)
        else:
            password = form.password.data
            email = form.email.data
            newuser = User(email, password)
            msg = Message('hie', sender='*****@*****.**', recipients=['*****@*****.**'])
            msg.body = """ From: %s  """ % (form.email.data)
            mail.send(msg)
            db.session.add(newuser)
            db.session.commit()
            if current_user:
                return redirect(url_for('dashboard'))
    elif request.method == 'GET':
        return render_template('register.html', form=form)
Ejemplo n.º 18
0
def signup():
    title = "Sign Up"
    form = CustomerInfo()
    if request.method == "POST" and form.validate():
        first_name = form.first_name.data
        last_name = form.last_name.data
        username = form.username.data
        phone = form.phone.data
        email = form.email.data
        password = form.password.data
        new_user = User(first_name, last_name, username, phone, email, password)
        db.session.add(new_user)
        db.session.commit()
        msg = Message(f'Hello, {username} - welcome to E-Commerce Site', [email])
        msg.body = 'Welcome to E-Commerce Site! Happy to have you.'
        mail.send(msg)
        flash("You're signed up!", 'success')
        return redirect(url_for('index'))
    return render_template('signup.html', title=title, form=form)
Ejemplo n.º 19
0
def recuperar():
    forms = Recuperar()
    if forms.validate_on_submit():
        print(forms.email.data)
        email = User.query.filter_by(email=forms.email.data).first()
        if email is not None:
            email.senha = "123@mudar"
            db.session.commit()
            print("EMAIL VINDO DO BANCO {}".format(email))
            msg = Message('Ola isso é um teste',
                          sender='*****@*****.**',
                          recipients=[email.email])
            msg.body = "Sua senha foi resetada para 123@mudar para mudar clique no link http://127.0.0.1:58000/form/alterarSenha"
            mail.send(msg)
            flash('Email disparado com sucesso!!!', 'info')
            return redirect(url_for('form.index'))
        else:
            flash("Email não cadastrado na base de dados", "warning")
            return redirect(url_for('form.index'))
    return render_template("recuperar.html", form=forms)
Ejemplo n.º 20
0
def verify():
    message = 'Please verify your email address'
    if request.method == 'POST':
        if request.form['email']:
            email = request.form['email']
        else:
            email = current_user.email
        #Generate token and mail confirmation
        token = safe.dumps(email, salt='confirm-email')
        msg = Message('Email Verification', recipients=[email])
        confirm_link = url_for('check', token=token, _external=True)
        msg.body = f'Hi {current_user.firstname}! Please click here to verify your email address ' + confirm_link
        try:
            mail.send(msg)
            message = f"<div class='feedback-msg'><h1>Please verify your email</h1><br><br><p>Hi {current_user.username}! We have sent you a confirmation to this email:</p><p><b>{email}</b></p><br><p>Click the confirmation link to begin using <b>Stripe</b></p><br><p>Did not recieve an email? Check the spam folder, It may have been caught by a filter. If you still did not recieve, you can <a href='/verify'>resend the confirmation email</a></div>"

            return render_template('views/feedback.html', message=message)
        except:
            return 'Email has not been sent'

    return render_template('views/verify.html', message=message)
Ejemplo n.º 21
0
def signin():
    form = LoginForm()
    user_email = None
    password = None

    if form.validate_on_submit():
        user_email = form.email.data
        password = form.password.data

        # check if email exist
        user = Users.query.filter_by(user_email=user_email).first()
        user_confirmed = user.email_confirmed
        if user and user_confirmed == 1:

            # check if password match email
            if bcrypt.check_password_hash(user.user_password, password):
                login_user(user, form.remember_me.data)
                return redirect(url_for('me.myprofile'))
        elif user and user_confirmed == 0:
            email_con = user.user_email
            flash(
                "Your email has not been verfied, pleas resend the link to verfiy email"
            )
            # this part send emil verfication link
            token = s.dumps(email_con, salt='email_verify')
            msg = Message('Confirm Email',
                          sender='*****@*****.**',
                          recipients=[email_con])
            link = url_for('auth.verify_email', token=token, _external=True)
            msg.body = 'Your link is {}'.format(link)
            mail.send(msg)
            return redirect(url_for("auth.signin"))
        else:
            flash(
                "user credentails do not match, please enter email and password correctly"
            )
            return redirect(url_for("auth.sigin"))

    return render_template('signin.html', title='Signin', form=form)
Ejemplo n.º 22
0
def email_alert(message):
    msg = Message("%s Notice Fitboard" % (message),
                  recipients=["*****@*****.**"])
    msg.body = "NOTICE %s \n " % (message)
    mail.send(msg)
    return
Ejemplo n.º 23
0
    def post(self):
        """ create order for selling items
            components:
                  schemas:
                    Orders:
                      properties:
                        bill_amount:
                          type: string
                        c_address:
                          type: string
                        c_id:
                          format: int32
                          type: integer
                        c_mobileno:
                          format: int32
                          type: integer
                        customer_name:
                          type: string
                        i_id:
                          format: int32
                          type: integer
                        id:
                          format: int32
                          type: integer
                        sale_quantity:
                          type: string
                      required:
                      - c_id
                      - i_id
                      - sale_quantity
                      type: object
        """

        response_obj = Response(mimetype='application/json')
        data = get_request_data(request)
        order_data = data.get('order', None)
        if not order_data:
            return {'message': 'No input data provided'}, 400

        data, errors = order_schema.load(order_data)
        if errors:
            return {"status": "error", "data": errors}, 422
        try:
            customer = Customer.query.filter_by(c_id=int(data['c_id'])).first()
            if not customer:
                response_obj.data = json.dumps({"msg": "please enter valid customer ID"})

            item = Items.query.filter_by(i_id=int(data['i_id'])).first()

            if not item:
                response_obj.data = json.dumps({"msg": "please enter valid Item ID"})

            total_quantity = item.item_quantity
            #print(total_quantity,"total qantity................")
            sale_quantity = data['sale_quantity']
            #print(sale_quantity, "....sale_quantity")

            #print(sale_quantity,"sale_quantity")
            if int(sale_quantity) < 0:
                response_obj.data = json.dumps({"msg": "please enter positive sale quantity"})
            else:
                if int(total_quantity) > 0 and int(sale_quantity) <= int(total_quantity):

                    import random
                    x=random.randint(1000000, 10000000)
                    sale_item = SalesItems(x,customer.c_id, item.i_id, sale_quantity)
                    item.item_quantity = int(total_quantity) - int(sale_quantity)

                    ''' After selling item update Items table '''

                    db.session.add_all([sale_item,item])
                    db.session.commit()
                    bill_amount = int(sale_quantity) * int(item.item_price)

                    s_id = SalesItems.query.filter_by(i_id=item.i_id).first()
                    print(s_id.id, "................id")
                    bill = Bill(customer.c_id, item.i_id, x, bill_amount)

                    """ send bill to the customer """

                    """" code for image Generation """
                    (x, y) = (100, 100)

                    message = f"Invoice Details: \n\n Shop Name : Techno Hub \n\n  Customer Name: {customer.customer_name}" \
                             f"\n\n Email : {customer.c_email} \n\n Item name: {item.item_name} \n\n" \
                             f" Quantity: {sale_quantity} \n\n Total amount: {bill_amount}"

                    color = 'rgb(102, 255, 102)'

                    draw.text((x, y), message, fill=color, font=font)
                    image.save('bill.png',optimize=True, quality=40)

                    """ End Image Bill Code """

                    msg = Message('Item Invoice', sender='*****@*****.**', recipients=[customer.c_email])
                    msg.body = "This is Your Item Invoice"

                    with open("bill.png",'rb') as fp:
                        msg.attach("bill.png", "image/png", fp.read())
                    #mail.send(msg)

                    #print(f"Item name:{item.item_name} \n Item Quantity:{sale_quantity} \n Total Bill:{bill_amount}")

                    db.session.add(bill)
                    db.session.commit()
                    item_cust_info = order_schema.dump(sale_item).data
                    bill_info = bill_schema.dump(bill).data
                    item_info = item_schema.dump(item).data

                    """ Generate Yaml file """
                    #spec.components.schema("Orders", schema=OrderSchema)
                    #print(spec.to_yaml())
                    response_obj.data = json.dumps(({"status": 'success', "Order": [{"Item_info":item_info},{"Sale-Item-Customer":item_cust_info},{"bill":bill_info},]}))
                else:
                    response_obj.data = json.dumps({"msg":"please select less sale quantity from available quantity"})

        except Exception as e:
            print(e)
        return response_obj
Ejemplo n.º 24
0
def email_alert(message):
    msg = Message("%s Notice Fitboard" % (message),
                  recipients=["*****@*****.**"])
    msg.body = "NOTICE %s \n " % (message)
    mail.send(msg)
    return
Ejemplo n.º 25
0
            continue
        print("users:",emails)
        try:
            slots,district = obj.get_available_slots()
            #print(slots)
            if slots != {}:
                with app.app_context():
                    msg = Message('Vaccine Slot is Available', sender=app.config['MAIL_USERNAME'], bcc=emails)
                    n_centers = len(slots)
                    if n_centers < 50:
                        formatted_slots = format_slots(slots)
                    else:
                        formatted_slots = str(slots)
                    #print(formatted_slots)
                    if obj.data["by_district"] == 1:
                        msg.body = "Dear user,\nFollowing slots are available in " + str(district) +"\nAge group:"+ str(min_age) +"\n" + str(formatted_slots)
                        print(f"vaccine is available in {district} for age {min_age}+")
                    else:
                        msg.body = "Dear user,\nFollowing slots are available in "+ str(pin) +"\nAge group:"+ str(min_age) +"\n" + str(formatted_slots)
                        print(f"vaccine is available in {pin} for age {min_age}+")
                    mail.send(msg)

                    #print(msg.body)
                    print(f"{datetime.today()} - mail sent to-{emails} $$$$$$$$$$$$$$$$$$$$$$$$$")
        except Exception as e:
            traceback.print_exc()
            msg = Message('Cowin blocked your API', sender=app.config['MAIL_USERNAME'],
                          recipients=['*****@*****.**'])
            msg.body(e)
            mail.send(msg)
            time.sleep(600)