示例#1
0
def notify_new_user_to_admin(user):
    admins = UserModel.get_admins()
    admin_emails = []
    for admin in admins:
        admin_emails.append(admin.email)
    send_email('New user registration!',
               sender=current_app.config['MAIL_DEFAULT_SENDER'],
               recipients=admin_emails,
               text_body=render_template('email/email_confirmation_notify.txt',
                                         user=user),
               html_body=render_template(
                   'email/email_confirmation_notify.html', user=user))
示例#2
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.welcome'))
    user = UserModel.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('user.login'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.new_password.data)
        db.session.commit()
        flash('Your password has been reset.', category='success')
        return redirect(url_for('user.login'))
    return render_template('flask_user/reset_password.html', form=form)
示例#3
0
def confirm(token):
    try:
        email = UserModel.confirm_token(token)
    except:
        flash('The confirmation link is invalid or has expired.', 'danger')
    user = UserModel.query.filter_by(email=email).first_or_404()
    if user.confirmed_at:
        flash('Account already confirmed. Please login.', 'success')
    else:
        user.confirmed_at = datetime.now()
        user.save_to_db()
        flash('You have confirmed your account. Thanks! Admin will send out email to you once complete reviewing your application', category='success')
    return redirect(url_for('main.welcome'))
示例#4
0
def confirm(token):
    try:
        email = UserModel.confirm_token(token)
    except:
        flash('The confirmation link is invalid or has expired.', 'danger')
    user = UserModel.query.filter_by(email=email).first_or_404()
    if user.confirmed_at:
        flash('Account already confirmed. Please login.', 'success')
    else:
        user.confirmed_at = datetime.now()
        user.save_to_db()
        notify_new_user_to_admin(user)
        flash('You have confirmed your account. Thanks!', 'success')
    return redirect(url_for('main.welcome'))
示例#5
0
def welcome():
    user = UserModel.find_by_email(current_user.email)
    if current_user.has_role("Admin"):
        return redirect(url_for('admin_views.upload_report'))
    else:
        user_upload_count = get_user_job_count()
        latest_history = UploadHistoryModel.get_last_by_user_id(
            user_id=user.id)
        if latest_history:
            catalog_type = CATALOG_TYPE.get(latest_history.catalog_type)
            status = JOB_STATUS.get(latest_history.status_id)
            return render_template('welcome.html',
                                   user=user,
                                   title='Welcome',
                                   latest_history=latest_history,
                                   catalog_type=catalog_type,
                                   status=status,
                                   user_upload_count=user_upload_count)
        else:
            return render_template('welcome.html', user=user, title='Welcome')
示例#6
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.welcome'))
    register_form = RegisterForm()
    if register_form.validate_on_submit():
        if request.form['user_note']:
            user_note = request.form['user_note']
        user = UserModel(username=register_form.username.data, email=register_form.email.data)
        user.set_password(register_form.password.data)
        user.save_to_db()
        email_confirmation(user)
        notify_new_user_to_admin(user, user_note)
        flash('Congratulations, you are now a registered user! '
              'A confirmation email has been sent via email.', category='success')
    return render_template('flask_user/login_or_register.html', register_form=register_form, form=register_form, login_form=register_form)
示例#7
0
 def validate_email(self, email):
     user = UserModel.find_by_email(email.data)
     if user is not None:
         raise ValidationError('Please use different email address.')
示例#8
0
 def validate_username(self, username):
     user = UserModel.find_by_username(username.data)
     if user is not None:
         raise ValidationError('Please use different username.')
示例#9
0
def company():
    form = CompanyForm()
    # print(form.validate_on_submit())
    if form.validate_on_submit():
        company_name_duplication = CompanyModel.find_by_name(form.name.data)
        if not form.id.data:
            if company_name_duplication:
                return jsonify(
                    {
                        "message":
                        "This company has already registered by other user"
                    }, 400)
            company = CompanyModel(
                name=form.name.data,
                description=form.description.data,
                address=form.address.data,
                telephone_number=form.telephone_number.data,
                toll_free_number=form.toll_free_number.data,
                fax_number=form.fax_number.data,
                website=form.website.data,
                sales_email=form.sales_email.data,
                personal_contact_name=form.personal_contact_name.data,
                personal_contact_email=form.personal_contact_email.data,
                idnumber=form.idnumber.data,
                cmpdname=form.cmpdname.data,
                cas=form.cas.data,
                price=form.price.data,
                job_notify_email=form.job_notify_email.data)
            if form.file.data:
                if check_img_type(form.file.data):
                    company.logo = save_file(form.file.data, form.name.data,
                                             True)
                else:
                    return False
            company.save_to_db()
            user = UserModel.find_by_email(current_user.email)
            user.company_id = company.id
            user.save_to_db()
        else:
            if company_name_duplication and company_name_duplication.id != int(
                    form.id.data):
                return jsonify(
                    {
                        "message":
                        "This company has already registered by other user"
                    }, 400)

            company = CompanyModel.find_by_id(int(form.id.data))
            if form.file.data:
                if check_img_type(form.file.data):
                    if current_app.config["ZINC_MODE"]:
                        company.logo = save_file(
                            form.file.data,
                            "{}_{}".format(current_user.id,
                                           form.name.data), True)
                    else:
                        company.logo = upload_file_to_s3(
                            form.file.data, form.name.data, "company-logos")
                else:
                    return False
            company.name = form.name.data
            company.description = form.description.data
            company.address = form.address.data
            company.telephone_number = form.telephone_number.data
            company.toll_free_number = form.toll_free_number.data
            company.fax_number = form.fax_number.data
            company.website = form.website.data
            company.sales_email = form.sales_email.data
            company.personal_contact_name = form.personal_contact_name.data
            company.personal_contact_email = form.personal_contact_email.data
            company.idnumber = form.idnumber.data
            company.cmpdname = form.cmpdname.data
            company.cas = form.cas.data
            company.price = form.price.data
            company.job_notify_email = form.job_notify_email.data
            company.save_to_db()
        flash('Updated!', category='success')
        return jsonify({"message": "Updated!"}, 200)
    elif request.method == 'GET':
        user = UserModel.find_by_email(current_user.email)
        if user.company:
            form.id.data = user.company_id
            form.logo.data = user.company.logo
            form.name.data = user.company.name
            form.description.data = user.company.description
            form.address.data = user.company.address
            form.telephone_number.data = user.company.telephone_number
            form.toll_free_number.data = user.company.toll_free_number
            form.fax_number.data = user.company.fax_number
            form.website.data = user.company.website
            form.sales_email.data = user.company.sales_email
            form.personal_contact_name.data = user.company.personal_contact_name
            form.personal_contact_email.data = user.company.personal_contact_email
            form.idnumber.data = user.company.idnumber
            form.cmpdname.data = user.company.cmpdname
            form.cas.data = user.company.cas
            form.price.data = user.company.price
            form.job_notify_email.data = user.company.job_notify_email
    return render_template('company.html', title='Profile', form=form)
示例#10
0
def welcome():
    user = UserModel.find_by_email(current_user.email)
    return render_template('welcome.html', user=user, title='Welcome')
示例#11
0
def verify_token(token):
    g.current_user = UserModel.check_token(token) if token else None
    return g.current_user is not None