Example #1
0
def register_page():
    #check if form has been submitted i.e., user has tried to register
    if (request.method == 'POST'):
        #get the data in name, email, and password fields
        name = request.form.get('name')
        email = request.form.get('email')
        
        # Validate email address
        if not validate(EMAIL_VALIDATION, email):
            flash("Invalid Email Address!", "danger")
            return render_template('register.html', json=json)

        password = request.form.get('password')
        
        # Validate password
        if not validate(PASSWORD_VALIDATION, password):
            flash("Invalid Password. Please enter a valid password!", "danger")
            return render_template('register.html', json=json)

        password2 = request.form.get('password2')
        #check if passwords match
        if(password!=password2):
            #if not, flash an error msg
            flash("Password unmatched!", "danger")
            return render_template('register.html', json=json)
        else:
            #generate the hashed password
            password = sha256_crypt.hash(password)
            response = Organization.query.filter_by(email=email).first()
            #check if the email already exists in the db
            if not response:
                #add the user to the db using the details entered and flash a msg
                entry = Organization(name=name, email=email, password=password, date=time, status=1)
                db.session.add(entry)
                db.session.commit()

                # Generate email verification token
                verification_token = generate_token(email)
                #generate the welcome email to be sent to the user
                subject = "Welcome aboard " + name + "!"

                content = render_template('email_template.html', token=verification_token, email=email)

                response = mail_handler(recepient_email=email,subject=subject, content=content)
                
                ## If any error occurs, the response will be equal to False 
                if isinstance(response, bool) and not response:    
                    flash("Error while sending mail!", "danger")
                else:
                    flash("Now verify your email address for activating your account.", "success")

                return redirect(url_for('login'))
            else:
                #user exists so flash an error
                flash("User exists!", "danger")
                return render_template('register.html', json=json)
    return render_template('register.html', json=json)
Example #2
0
def forgot_password_page():
    # check if form has been submitted
    if request.method == "POST":
        # get the email entered
        email = request.form.get("email")
        # get the user from the db
        post = User.query.filter_by(email=email).first()
        if post:
            # if user exists
            if post.is_staff:
                # if user tried to reset admin password
                flash("You can't reset password of administrator!", "danger")
                return render_template("forgot-password.html",
                                       favTitle=favTitle)
            else:
                # Generate email verification token
                verification_token = generate_token(email)
                print(
                    url_for('reset_password',
                            token=verification_token,
                            email=email))
                # generate the email to be sent to the user
                subject = "Password Reset Link | BulkMailer"
                content = render_template("emails/forgot-pwd.html",
                                          token=verification_token,
                                          email=email)
                response = mail_handler(recepient_email=email,
                                        subject=subject,
                                        content=content,
                                        name="Password Bot | Bulk Mailer")
                # If any error occurs, the response will be equal to False
                if isinstance(response, bool) and not response:
                    flash("Error while sending mail!", "danger")
                else:
                    flash(
                        f"We've sent a password reset link on {email}!",
                        "success",
                    )
        else:
            # user doesn't exist
            flash("We didn't find your account!", "danger")
            return render_template("forgot-password.html", favTitle=favTitle)

    return render_template("forgot-password.html", favTitle=favTitle)
Example #3
0
def register_page():
    # check if form has been submitted i.e., user has tried to register
    if request.method == "POST":
        # get the data in name, email, and password fields
        name = request.form.get("name")
        email = request.form.get("email")
        profile_image = avatar(email, 128)
        # Validate email address
        if not validate(EMAIL_VALIDATION, email):
            flash("Invalid Email Address!", "danger")
            return render_template("register.html", favTitle=favTitle)

        password = request.form.get("password")

        # Validate password
        if not validate(PASSWORD_VALIDATION, password):
            flash("Invalid Password. Please enter a valid password!", "danger")
            return render_template("register.html", favTitle=favTitle)

        password2 = request.form.get("password2")
        # check if passwords match
        if password != password2:
            # if not, flash an error msg
            flash("Password unmatched!", "danger")
            return render_template("register.html", favTitle=favTitle)
        else:
            # generate the hashed password
            password = sha256_crypt.hash(password)
            response = User.query.filter_by(email=email).first()
            # check if the email already exists in the db
            if not response:
                # add the user to the db using the details entered and flash a msg
                entry = User(
                    name=name,
                    email=email,
                    password=password,
                    date=time,
                    profile_image=profile_image,
                    status=1,
                    is_staff=False,
                )
                db.session.add(entry)
                db.session.commit()

                # Generate email verification token
                verification_token = generate_token(email)
                print(
                    url_for('verify_email',
                            token=verification_token,
                            email=email))
                # generate the welcome email to be sent to the user
                subject = "Welcome aboard " + name + "!"

                content = render_template("emails/register.html",
                                          token=verification_token,
                                          email=email)

                response = mail_handler(recepient_email=email,
                                        subject=subject,
                                        content=content,
                                        name="Register Bot | Bulk Mailer")

                # If any error occurs, the response will be equal to False
                if isinstance(response, bool) and not response:
                    flash("Error while sending mail!", "danger")
                else:
                    flash(
                        "Now verify your email address for activating your account.",
                        "success",
                    )

                return redirect(url_for("login"))
            else:
                # user exists so flash an error
                flash("User exists!", "danger")
                return render_template("register.html", favTitle=favTitle)
    return render_template("register.html", favTitle=favTitle)
Example #4
0
def register_page():
    #check if form has been submitted i.e., user has tried to register
    if (request.method == 'POST'):
        #get the data in name, email, and password fields
        name = request.form.get('name')
        email = request.form.get('email')

        # Validate email address
        if not validate(EMAIL_VALIDATION, email):
            flash("Invalid Email Address!", "danger")
            return render_template('register.html', json=json)

        password = request.form.get('password')

        # Validate password
        if not validate(PASSWORD_VALIDATION, password):
            flash("Invalid Password. Please enter a valid password!", "danger")
            return render_template('register.html', json=json)

        password2 = request.form.get('password2')
        #check if passwords match
        if (password != password2):
            #if not, flash an error msg
            flash("Password unmatched!", "danger")
            return render_template('register.html', json=json)
        else:
            #generate the hashed password
            password = sha256_crypt.hash(password)
            response = Organization.query.filter_by(email=email).first()
            #check if the email already exists in the db
            if not response:
                #add the user to the db using the details entered and flash a msg
                entry = Organization(name=name,
                                     email=email,
                                     password=password,
                                     date=time,
                                     status=1)
                db.session.add(entry)
                db.session.commit()
                flash(
                    "Now contact your organization head for account activation!",
                    "success")
                # Generate email verification token

                verification_token = generate_token(email)
                #generate the welcome email to be sent to the user
                subject = "Welcome aboard " + name + "!"

                # content = '''<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Reset Your Password</title> <!--[if !mso]> --><meta http-equiv="X-UA-Compatible" content="IE=edge"> <!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><style type="text/css">#outlook a{padding:0}.ReadMsgBody{width:100%}.ExternalClass{width:100%}.ExternalClass *{line-height:100%}body{margin:0;padding:0;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}table,td{border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt}img{border:0;height:auto;line-height:100%;outline:none;text-decoration:none;-ms-interpolation-mode:bicubic}p{display:block;margin:13px 0}</style><style type="text/css">@media only screen and (max-width:480px){@-ms-viewport{width:320px}@viewport{width:320px}}</style><style type="text/css">@media only screen and (min-width:480px){.mj-column-per-100{width:100%!important}}</style></head><body style="background: #f0f0f0;"><div class="mj-container" style="background-color:#f0f0f0;"><table role="presentation" cellpadding="0" cellspacing="0" style="background:#f0f0f0;font-size:0px;width:100%;" border="0"><tbody><tr><td><div style="margin:0px auto;max-width:600px;"><table role="presentation" cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;" align="center" border="0"><tbody><tr><td style="text-align:center;vertical-align:top;direction:ltr;font-size:0px;padding:0px 0px 0px 0px;"><div class="mj-column-per-100 outlook-group-fix" style="vertical-align:top;display:inline-block;direction:ltr;font-size:13px;text-align:left;width:100%;"><table role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0"><tbody><tr><td style="word-wrap:break-word;font-size:0px;"><div style="font-size:1px;line-height:30px;white-space:nowrap;">&#xA0;</div></td></tr></tbody></table></div></td></tr></tbody></table></div></td></tr></tbody></table><div style="margin:0px auto;max-width:600px;background:#FFFFFF;"><table role="presentation" cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;background:#FFFFFF;" align="center" border="0"><tbody><tr><td style="text-align:center;vertical-align:top;direction:ltr;font-size:0px;padding:9px 0px 9px 0px;"><div class="mj-column-per-100 outlook-group-fix" style="vertical-align:top;display:inline-block;direction:ltr;font-size:13px;text-align:left;width:100%;"><table role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0"><tbody><tr><td style="word-wrap:break-word;font-size:0px;padding:25px 25px 25px 25px;" align="center"><table role="presentation" cellpadding="0" cellspacing="0" style="border-collapse:collapse;border-spacing:0px;" align="center" border="0"><tbody><tr><td style="width:204px;"> <img alt="" title="" height="100px" width="100px" src="https://cdn.discordapp.com/attachments/577137963985534994/791571694803353610/favicon.ico" style="border:none;border-radius:0px;display:block;font-size:13px;outline:none;text-decoration:none;width:100%;height:auto;" width="204"></td></tr></tbody></table></td></tr><tr><td style="word-wrap:break-word;font-size:0px;padding:0px 15px 0px 15px;" align="center"><div style="cursor:auto;color:#333333;font-family:Helvetica, sans-serif;font-size:15px;line-height:22px;text-align:center;"><h3 style="font-family: Helvetica, sans-serif; font-size: 24px; color: #333333; line-height: 50%;">Hey, Welcome!</h3></div></td></tr><tr><td style="word-wrap:break-word;font-size:0px;padding:0px 50px 0px 50px;" align="center"><div style="cursor:auto;color:#333333;font-family:Helvetica, sans-serif;font-size:15px;line-height:22px;text-align:center;"><p>Now click <a href="{verification_token}">here</a> to verify your email address.</p></div></td></tr><tr><td style="word-wrap:break-word;font-size:0px;padding:20px 25px 20px 25px;padding-top:10px;padding-left:25px;" align="center"><table role="presentation" cellpadding="0" cellspacing="0" style="border-collapse:separate;" align="center" border="0"><tbody><tr><td style="border:none;border-radius:5px;color:#FFFFFF;cursor:auto;padding:10px 25px;" align="center" valign="middle" bgcolor="#4DAA50"><a href="https://bulkmailer.cf" style="text-decoration: none; background: #4DAA50; color: #FFFFFF; font-family: Helvetica, sans-serif; font-size: 19px; font-weight: normal; line-height: 120%; text-transform: none; margin: 0px;" target="_blank">Visit Website</a></td></tr></tbody></table></td></tr><tr><td style="word-wrap:break-word;font-size:0px;padding:0px 47px 0px 47px;" align="center"><div style="cursor:auto;color:#333333;font-family:Helvetica, sans-serif;font-size:15px;line-height:22px;text-align:center;"><p><span style="font-size:14px;"><strong>Questions?&#xA0;</strong><br>Email us at <a href="mailto:[email protected]" style="color: #555555;">[email protected]</a>.&#xA0;</span></p></div></td></tr></tbody></table></div></td></tr></tbody></table></div><table role="presentation" cellpadding="0" cellspacing="0" style="background:#f0f0f0;font-size:0px;width:100%;" border="0"><tbody><tr><td><div style="margin:0px auto;max-width:600px;"><table role="presentation" cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;" align="center" border="0"><tbody><tr><td style="text-align:center;vertical-align:top;direction:ltr;font-size:0px;padding:0px 0px 0px 0px;"><div class="mj-column-per-100 outlook-group-fix" style="vertical-align:top;display:inline-block;direction:ltr;font-size:13px;text-align:left;width:100%;"><table role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0"><tbody><tr><td style="word-wrap:break-word;font-size:0px;padding:0px 98px 0px 98px;" align="center"><div style="cursor:auto;color:#777777;font-family:Helvetica, sans-serif;font-size:15px;line-height:22px;text-align:center;"><p><span style="font-size:12px;"><a href="https://bulkmailer.cf" style="color: #555555;">TERMS OF SERVICE</a> | <a href="https://bulkmailer.cf" style="color: #555555;">PRIVACY POLICY</a><br>&#xA9; 2020 Bulk Mailer<br><a href="https://bulkmailer.cf/unsubscribe" style="color: #555555;">UNSUBSCRIBE</a></span></p></div></td></tr></tbody></table></div></td></tr></tbody></table></div></td></tr></tbody></table></div></body></html>'''
                content = render_template('email_template.html',
                                          token=verification_token)
                # content.format(verification_token)
                response = mail_handler(recepient_email=email,
                                        subject=subject,
                                        content=content)

                ## If any error occurs, the response will be equal to False
                if isinstance(response, bool) and not response:
                    flash("Error while sending mail!", "danger")

                return redirect(url_for('login'))
            else:
                #user exists so flash an error
                flash("User exists!", "danger")
                return render_template('register.html', json=json)
    return render_template('register.html', json=json)