Exemple #1
0
def candidate(uid):
    user = savvy_collection.find_one({ '_id': ObjectId(uid) })
    if user and user.get(CATEGORY) == CAND:
        return render('candidate.html', extra=user)
    else:
        flash('Invalid access to account', 'error')
        return redirect(url_for('home'))
Exemple #2
0
def load_user(email):
    if email != None:
        user = savvy_collection.find_one({EMAIL: email})
        if user:
            return User(user)

    return None
def jobExperienceEdit():
    user = savvy_collection.find_one({ EMAIL: current_user.get_id()[EMAIL] })

    if user:
        if request.method == 'POST':
            print (request.data)
            print (request.form)
            print (request.json)
            print("Edited")

            jobExperienceId = request.json['jobExperienceId']
            returnString = '#jobExperience'+jobExperienceId

            entry = {
                'position'      : request.json['position'],
                'company'       : request.json['company'],
                'period'        : request.json['period'],
                'description'   : request.json['description']
            }

            old = user['jobExperience']
            print (old)
            old[str(jobExperienceId)] = entry
            print (old)
            savvy_collection.update({EMAIL:user[EMAIL]}, {"$set": {JOBEXPERIENCE: old}})

            # return information to frontend
            return jsonify(returnString = returnString)
Exemple #4
0
    def validate(self):
        rv = Form.validate(self)
        if not rv:
            message = ''
            for fieldName, errorMessages in self.errors.items():
                for err in errorMessages:
                    message = message + fieldName + ': ' + err + '\n'
            flash(message, 'error')
            return False

        # Query data from database
        user = savvy_collection.find_one({EMAIL: self.email.data.rstrip()})

        if user:
            email = user.get(EMAIL, None)
            hash_password = user.get(PASSWORD, None)
            user_password = self.password.data.rstrip()
            account_token = user.get(TOKEN, '')

            if User.validate_login(hash_password, user_password):
                userObj = User(email)
                login_user(userObj)
                return True
            else:
                flash('Incorrect login credentials', 'error')
        else:
            flash('Incorrect login credentials', 'error')
        return False
Exemple #5
0
    def validate(self):
        rv = Form.validate(self)
        if not rv:
            message = ''
            for fieldName, errorMessages in self.errors.items():
                for err in errorMessages:
                    message = message + fieldName + ': ' + err + '\n'
            flash(message, 'error')
            return False

        # Query data from database
        user = savvy_collection.find_one({ EMAIL: self.email.data.rstrip() })

        if user:
            email = user.get(EMAIL, None)
            hash_password = user.get(PASSWORD, None)
            user_password = self.password.data.rstrip()
            account_token = user.get(TOKEN, '')

            if User.validate_login(hash_password, user_password):
                userObj = User(email)
                login_user(userObj)
                return True
            else:
                flash('Incorrect login credentials', 'error')
        else:
            flash('Incorrect login credentials', 'error')
        return False
Exemple #6
0
    def validate(self):
        rv = Form.validate(self)
        if not rv:
            message = ''
            for fieldName, errorMessages in self.errors.items():
                for err in errorMessages:
                    message = message + fieldName + ': ' + err + '\n'
            flash(message, 'error')
            return False

        user = savvy_collection.find_one({EMAIL: self.email.data.rstrip()})
        if user:
            flash('Email has already been taken', 'warning')
            return False
        else:
            raw_token = self.email.data + 'verification code'
            token = md5(raw_token.encode('utf-8')).hexdigest()
            user = {
                PASSWORD:
                md5(self.password.data.rstrip().encode('utf-8')).hexdigest(),
                EMAIL:
                self.email.data.rstrip(),
                CATEGORY:
                self.category.data,
                TOKEN:
                token
            }

            # insert into database
            employerId = savvy_collection.insert_one(user).inserted_id

            if self.category.data == EMPL:
                jobs_collection.insert({EMPLID: employerId})

            # url = os.getenv('SCRIPT_URI') <----------------get this to work when server is up
            # url = '127.0.0.1:5000'
            # message = """
            # Hi {},
            #
            #     You need to confirm your account by clicking this link:
            #     {}/confirmEmail/{}/{}
            #
            # Best,
            # Team SavvyHire
            # """.format(self.username.data.rstrip(),url, self.username.data.rstrip(), token)
            #
            # cmd="""echo '{}' | mail -s 'Confirm account' {}""".format(message, self.email.data.rstrip())
            # p=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
            # p.communicate()

            # log in
            userObj = User(user[EMAIL])
            login_user(userObj)

            return True
Exemple #7
0
def changepassword(email, password):
    user = savvy_collection.find_one({EMAIL: email})
    form = changepasswordForm(request.form, user)

    if user:
        if User.validate_password(email, password):
            print(user)
            print('validated')
            print(current_user.get_id())
            return render('changepassword.html', form=form, extra=email)

    return redirect(url_for('home'))
def changepassword(email, password):
    user = savvy_collection.find_one({ EMAIL: email })
    form = changepasswordForm(request.form,user)

    if user:
        if User.validate_password(email, password):
            print (user)
            print('validated')
            print(current_user.get_id())
            return render('changepassword.html', form=form, extra=email)

    return redirect(url_for('home'))
Exemple #9
0
    def validate(self):
        rv = Form.validate(self)
        if not rv:
            message = ""
            for fieldName, errorMessages in self.errors.items():
                for err in errorMessages:
                    message = message + fieldName + ": " + err + "\n"
            flash(message, "error")
            return False

        user = savvy_collection.find_one({EMAIL: self.email.data.rstrip()})
        if user:
            flash("Email has already been taken", "warning")
            return False
        else:
            raw_token = self.email.data + "verification code"
            token = md5(raw_token.encode("utf-8")).hexdigest()
            user = {
                PASSWORD: md5(self.password.data.rstrip().encode("utf-8")).hexdigest(),
                EMAIL: self.email.data.rstrip(),
                CATEGORY: self.category.data,
                TOKEN: token,
            }

            # insert into database
            employerId = savvy_collection.insert_one(user).inserted_id

            if self.category.data == EMPL:
                jobs_collection.insert({EMPLID: employerId})

            # url = os.getenv('SCRIPT_URI') <----------------get this to work when server is up
            # url = '127.0.0.1:5000'
            # message = """
            # Hi {},
            #
            #     You need to confirm your account by clicking this link:
            #     {}/confirmEmail/{}/{}
            #
            # Best,
            # Team SavvyHire
            # """.format(self.username.data.rstrip(),url, self.username.data.rstrip(), token)
            #
            # cmd="""echo '{}' | mail -s 'Confirm account' {}""".format(message, self.email.data.rstrip())
            # p=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
            # p.communicate()

            # log in
            userObj = User(user[EMAIL])
            login_user(userObj)

            return True
Exemple #10
0
def postJob():
    email = current_user.get_id()[EMAIL]
    user = savvy_collection.find_one({ EMAIL: email })
    if user and user.get(CATEGORY, None) == EMPL:
        form = jobForm(request.form)

        if request.method == 'POST' and form.validate():
            form.update(user)
            flash('successfully updated your job post', 'success')
            return redirect(url_for('account') + '#step4')

        return render('job.html', form = form)
    else:
        flash('Invalid access to account', 'error')
        return redirect(url_for('home'))
Exemple #11
0
def postJob():
    email = current_user.get_id()[EMAIL]
    user = savvy_collection.find_one({EMAIL: email})
    if user and user.get(CATEGORY, None) == EMPL:
        form = jobForm(request.form)

        if request.method == 'POST' and form.validate():
            form.update(user)
            flash('successfully updated your job post', 'success')
            return redirect(url_for('account') + '#step4')

        return render('job.html', form=form)
    else:
        flash('Invalid access to account', 'error')
        return redirect(url_for('home'))
Exemple #12
0
    def validate_rego_token(email, token):
        user = savvy_collection.find_one({ EMAIL: email })
        if user:
            token_db = user.get(TOKEN, None)
            if token_db != None:
                if token_db == token:
                    update = savvy_collection.update_one( {EMAIL: email}, {'$set': {TOKEN: ''}} )
                    flash('Your account has been verified!', 'success')
                    return True
                elif token_db == '':
                    flash('Account has already been verified', 'warning')
                    return False

        flash('Unknown confirmation link', 'error')
        return False
Exemple #13
0
def jobExperience():
    user = savvy_collection.find_one({EMAIL: current_user.get_id()[EMAIL]})
    if user:
        if request.method == 'POST':
            print(request.data)
            print(request.form)
            print(request.json)
            print("Deleted")

            returnString = request.json
            company = request.json['company']
            period = request.json['period']
            position = request.json['position']
            description = request.json['description']

            if position and company and period and description:

                entry = {
                    'position': position,
                    'company': company,
                    'period': period,
                    'description': description
                }

                oldDic = user.get('jobExperience')
                if oldDic:
                    newIndex = int(max(oldDic.keys()))
                    newDic = OrderedDict()
                    newDic = oldDic
                    newDic[str(newIndex + 1)] = entry
                    savvy_collection.update(
                        {EMAIL: user[EMAIL]},
                        {"$set": {
                            'jobExperience': newDic
                        }})

                else:
                    oldDic = OrderedDict()
                    oldDic['1'] = entry
                    savvy_collection.update(
                        {EMAIL: user[EMAIL]},
                        {"$set": {
                            'jobExperience': oldDic
                        }})

            # return information to frontend
            return jsonify(returnString=returnString)
Exemple #14
0
def change():
    email = request.form[EMAIL]
    user = savvy_collection.find_one({EMAIL: email})
    form = None
    if email:
        if user:
            form = changepasswordForm(request.form, user)

            if request.method == 'GET':
                return render('changepassword.html', form=form)

            if request.method == 'POST' and form.validate():
                print('validated')
                return redirect(url_for('home'))

        return render('changepassword.html', form=form, extra=email)
    else:
        return redirect(url_for('home'))
Exemple #15
0
    def validate_rego_token(email, token):
        user = savvy_collection.find_one({EMAIL: email})
        if user:
            token_db = user.get(TOKEN, None)
            if token_db != None:
                if token_db == token:
                    update = savvy_collection.update_one({EMAIL: email},
                                                         {'$set': {
                                                             TOKEN: ''
                                                         }})
                    flash('Your account has been verified!', 'success')
                    return True
                elif token_db == '':
                    flash('Account has already been verified', 'warning')
                    return False

        flash('Unknown confirmation link', 'error')
        return False
Exemple #16
0
def change():
    email = request.form[EMAIL]
    user = savvy_collection.find_one({ EMAIL: email })
    form=None
    if email:
        if user:
            form = changepasswordForm(request.form,user)

            if request.method == 'GET':
                return render('changepassword.html', form=form)

            if request.method == 'POST' and form.validate():
                print('validated')
                return redirect(url_for('home'))

        return render('changepassword.html', form=form, extra=email)
    else:
        return redirect(url_for('home'))
Exemple #17
0
def deleteJobPost():
    user = savvy_collection.find_one({ EMAIL: current_user.get_id()[EMAIL] })
    if user:
        if request.method == 'POST':
            jobId = request.json['jobId']
            listId = request.json['listId']
            returnString = "#jobajax" + str(listId)
            employerId = user['_id']

            # Update savvy collection
            savvy_collection.update({EMAIL: user[EMAIL]},
                                    {"$pull": {'jobs': jobId}})

            # Delete job from job collection
            jobs_collection.update({EMPLOYERID: employerId},
                                   {"$unset": {jobId: ''}})

            # return information to frontend
            return jsonify(returnString = returnString)
def jobExperienceRemove():
    user = savvy_collection.find_one({ EMAIL: current_user.get_id()[EMAIL] })
    if user:
        if request.method == 'POST':
            print (request.data)
            print (request.form)
            print (request.json)
            print("Deleted")

            jobExperienceId = request.json['jobExperienceId']
            returnString = '#jobExperience'+jobExperienceId

            old = user['jobExperience']
            del old[jobExperienceId]

            savvy_collection.update({EMAIL: user[EMAIL]}, {"$set": {JOBEXPERIENCE: old}})

            # return information to frontend
            return jsonify(returnString = returnString)
Exemple #19
0
def editJobPost():
    user = savvy_collection.find_one({EMAIL: current_user.get_id()[EMAIL]})
    if user:
        if request.method == 'POST':
            print(request.data)
            print(request.form)
            print(request.json)
            jobId = request.json['jobId']
            listId = request.json['listId']
            position = request.json['position']
            availability = request.json['availability']
            residency = request.json['residency']
            location = request.json['location']
            description = request.json['description']
            print('jobId = ' + jobId + ' listId = ' + listId)
            returnString = "#jobajax" + str(listId)

            employerId = user['_id']

            jobEntry = {
                TITLE: position,
                AVAILABILITY: availability,
                DESCRIPTION: description,
                RESIDENCY: residency,
                LOCATION: location,
                EMPLOYERID: employerId,
                TYPE: JOB,
                BUSINESS: user.get(BUSINESS, ''),
                WEBSITE: user.get(WEBSITE, ''),
                ABOUT: user.get(ABOUT, '')
            }

            jobs_collection.update({EMPLOYERID: employerId},
                                   {"$set": {
                                       jobId: jobEntry
                                   }})

            print("Edited")

            # return information to frontend
            return jsonify(returnString=returnString)
def jobExperienceRemove():
    user = savvy_collection.find_one({EMAIL: current_user.get_id()[EMAIL]})
    if user:
        if request.method == 'POST':
            print(request.data)
            print(request.form)
            print(request.json)
            print("Deleted")

            jobExperienceId = request.json['jobExperienceId']
            returnString = '#jobExperience' + jobExperienceId

            old = user['jobExperience']
            del old[jobExperienceId]

            savvy_collection.update({EMAIL: user[EMAIL]},
                                    {"$set": {
                                        JOBEXPERIENCE: old
                                    }})

            # return information to frontend
            return jsonify(returnString=returnString)
Exemple #21
0
def jobExperience():
    user = savvy_collection.find_one({ EMAIL: current_user.get_id()[EMAIL] })
    if user:
        if request.method == 'POST':
            print(request.data)
            print(request.form)
            print(request.json)
            print("Deleted")

            returnString = request.json
            company = request.json['company']
            period = request.json['period']
            position = request.json['position']
            description = request.json['description']

            if position and company and period and description:

                entry = {
                    'position'      : position,
                    'company'       : company,
                    'period'        : period,
                    'description'   : description
                }

                oldDic = user.get('jobExperience')
                if oldDic:
                    newIndex = int(max(oldDic.keys()))
                    newDic = OrderedDict()
                    newDic = oldDic
                    newDic[str(newIndex + 1)] = entry
                    savvy_collection.update({EMAIL:user[EMAIL]}, {"$set": {'jobExperience': newDic}})

                else:
                    oldDic = OrderedDict()
                    oldDic['1'] = entry
                    savvy_collection.update({EMAIL: user[EMAIL]}, {"$set": {'jobExperience': oldDic}})

            # return information to frontend
            return jsonify(returnString = returnString)
Exemple #22
0
def editJobPost():
    user = savvy_collection.find_one({ EMAIL: current_user.get_id()[EMAIL] })
    if user:
        if request.method == 'POST':
            print (request.data)
            print (request.form)
            print (request.json)
            jobId = request.json['jobId']
            listId = request.json['listId']
            position = request.json['position']
            availability = request.json['availability']
            residency = request.json['residency']
            location = request.json['location']
            description = request.json['description']
            print ('jobId = ' + jobId + ' listId = ' + listId)
            returnString = "#jobajax" + str(listId)

            employerId = user['_id']

            jobEntry = {
                TITLE       : position,
                AVAILABILITY: availability,
                DESCRIPTION : description,
                RESIDENCY   : residency,
                LOCATION    : location,
                EMPLOYERID  : employerId,
                TYPE        : JOB,
                BUSINESS    : user.get(BUSINESS,''),
                WEBSITE     : user.get(WEBSITE,''),
                ABOUT       : user.get(ABOUT,'')
            }

            jobs_collection.update({EMPLOYERID: employerId}, {"$set": {jobId: jobEntry}})

            print("Edited")

            # return information to frontend
            return jsonify(returnString = returnString)
Exemple #23
0
def deleteJobPost():
    user = savvy_collection.find_one({EMAIL: current_user.get_id()[EMAIL]})
    if user:
        if request.method == 'POST':
            jobId = request.json['jobId']
            listId = request.json['listId']
            returnString = "#jobajax" + str(listId)
            employerId = user['_id']

            # Update savvy collection
            savvy_collection.update({EMAIL: user[EMAIL]},
                                    {"$pull": {
                                        'jobs': jobId
                                    }})

            # Delete job from job collection
            jobs_collection.update({EMPLOYERID: employerId},
                                   {"$unset": {
                                       jobId: ''
                                   }})

            # return information to frontend
            return jsonify(returnString=returnString)
Exemple #24
0
def account():
    user = savvy_collection.find_one({ EMAIL: current_user.get_id()[EMAIL] })
    userJob = jobs_collection.find_one({'employerId': user.get('_id', '')})
    if user:
        form = None
        if user.get(CATEGORY, '') == EMPL:
            form = employerForm(user, request.form)
        elif user.get(CATEGORY, '') == CAND:
            form = candidateForm(user, request.form)

        if request.method == 'GET':
            form.prepopulate(user)

        if request.method == 'POST':
            if form.validate():
                form.update(user.get(EMAIL))

        return render('account.html', form=form,
                                      error=None,
                                      jsonObject=None,
                                      extra=userJob)
    else:
        flash('Invalid access to account', 'error')
        return redirect(url_for('home'))
Exemple #25
0
    def validate(self):
        rv = Form.validate(self)
        if not rv:
            message = ''
            for fieldName, errorMessages in self.errors.items():
                for err in errorMessages:
                    message = message + fieldName + ': ' + err + '\n'
            flash(message, 'error')
            return False

        user = savvy_collection.find_one({ EMAIL : self.email.data.rstrip() })
        if user:
            # send email with new password to this address
            link = "http://savvyhire.herokuapp.com/changepassword"

            img_data = open('app/static/images/logo.png', 'rb').read()
            msg = MIMEMultipart('alternative')
            msg['Subject'] = 'Password recovery!'
            msg['From'] = '*****@*****.**'
            msg['To'] = user['email']
            From = '*****@*****.**'
            To = user['email']

            text = """Hi {},\nYou have forgotten your password, but that's alright!\nClick this link to change your password:\n"{}/{}/{}"\nBest,\nTeam SavvyHire
            """.format(user.get('firstName'), link, user.get('email'), user.get('password'))

            bodyStyle = """
                background: #F3F4F5;
                padding: .71428571rem 1rem;
                box-shadow: none;
                border: 1px solid #D4D4D5;
                border-radius: .28571429rem;
                font-family: Lato,'Helvetica Neue',Arial,Helvetica,sans-serif;
            """
            greetStyle = """
                font-weight: 500;
                font-size: 27px;
            """
            contentStyle = """
                margin-bottom: 10px;
                margin-top: 5px;
                font-weight: normal;
                font-size: 17px;
                line-height: 1.6;
            """
            messageStyle = """
                margin-bottom: 4%;
                line-height: 2;
                display: block;
                background: #FFF;
                border: 1px solid rgba(133, 183, 217,.5);
                padding-top: 3%;
                padding-left: 7%;
                border-radius: 0.285714rem;
            """

            html = """\
            <html>
              <head></head>
              <body style="{}">
                <p><span style="{}">Hi {},<br><br></span>
                   <span style="{}">
                   You have forgotten your password, but that's alright!<br><br>
                   Click this link to change your password:<br><br>
                   <span style="{}"
                   <i>{}/{}/{}</i><br><br>
                   </span>
                   Best,<br>
                   Team SavvyHire<br>
                   </span>
                </p>
                <img src="https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xap1/v/t1.0-9/12552797_946970445338090_4081041973572931633_n.png?oh=3657d0fd2ab010f7b752f825c16070ba&oe=572DAC6A&__gda__=1463629238_96cd9ea3062bfbbb1539e9cdfb18ad25" style="width:150px;">
              </body>
            </html>
            """.format(bodyStyle, greetStyle, user.get('firstName',''), contentStyle, messageStyle, link, user.get('email'), user.get('password'))

            # Record the MIME types of both parts - text/plain and text/html.
            part1 = MIMEText(text, 'plain')
            part2 = MIMEText(html, 'html')

            # Attach parts into message container.
            # According to RFC 2046, the last part of a multipart message, in this case
            # the HTML message, is best and preferred.
            msg.attach(part1)
            msg.attach(part2)

            image = MIMEImage(img_data, name=os.path.basename('app/static/images/logo.png'))
            msg.attach(image)

            s = smtplib.SMTP('smtp.gmail.com:587')
            username = "******"
            password = '******'
            s.ehlo()
            s.starttls()
            s.ehlo()
            s.login(username, password)
            s.sendmail(From, To, msg.as_string())
            s.quit()

            return True
        else:
            flash("{} doesn't exisit in our database".format(self.email.data), 'error')
            return False
Exemple #26
0
def applyJobs():
    if request.method == "POST":
        print(request.form)
        message = request.form["applyJobMsg"]
        employerId = request.form["employerId"]
        employerId = ObjectId(employerId)
        modal = request.form["modalId"]
        jobSeekerId = request.form["jobSeeker"]
        jobSeekerId = ObjectId(jobSeekerId)
        title = request.form["title"]

        # print(modal)
        jobSeeker = savvy_collection.find_one({"_id": jobSeekerId})
        user = savvy_collection.find_one({"_id": employerId})

        print(employerId)
        print(request.form)

        if user:
            # Send an email
            img_data = open("app/static/images/logo.png", "rb").read()
            msg = MIMEMultipart("alternative")
            msg["Subject"] = "{} {} applied for your {} position on SavvyHire".format(
                jobSeeker.get("firstName", ""), jobSeeker.get("lastName", "Someone"), title
            )
            msg["From"] = "*****@*****.**"
            msg["To"] = user["email"]
            From = "*****@*****.**"
            To = user["email"]

            text = """{} {} applied for your {} job!\nHere's the message:\n"{}"\nBest,\nTeam SavvyHire
            """.format(
                jobSeeker.get("firstName", ""), jobSeeker.get("lastName", "Someone"), title, message
            )

            bodyStyle = """
                background: #F3F4F5;
                padding: .71428571rem 1rem;
                box-shadow: none;
                border: 1px solid #D4D4D5;
                border-radius: .28571429rem;
                font-family: Lato,'Helvetica Neue',Arial,Helvetica,sans-serif;
            """
            greetStyle = """
                font-weight: 500;
                font-size: 27px;
            """
            contentStyle = """
                margin-bottom: 10px;
                margin-top: 5px;
                font-weight: normal;
                font-size: 17px;
                line-height: 1.6;
            """
            messageStyle = """
                margin-bottom: 4%;
                line-height: 2;
                display: block;
                background: #FFF;
                border: 1px solid rgba(133, 183, 217,.5);
                padding: 1%;
                border-radius: 0.285714rem;
                white-space: PRE;
                word-wrap: break-word;
            """

            html = """\
            <html>
              <head></head>
              <body style="{}">
                <p><span style="{}">{} {} applied for your {} job!<br><br></span>
                   <span style="{}">
                   Here's their cover letter:<br><br>
                   <span style="{}"
                   <i>{}</i>
                   </span>
                   Here's the link to their digital cv:<br>
                   http://savvyhire.herokuapp.com/candidate/{}
                   <br><br>
                   Here's the email for you to contact directly: <a href="mailto:{}">{}</a>  <small style="color:rgb(17, 166, 86);">click it!</small>
                   <br><br>
                   Best,<br>
                   Team SavvyHire<br>
                   </span>
                </p>
                <img src="https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xap1/v/t1.0-9/12552797_946970445338090_4081041973572931633_n.png?oh=3657d0fd2ab010f7b752f825c16070ba&oe=572DAC6A&__gda__=1463629238_96cd9ea3062bfbbb1539e9cdfb18ad25" style="width:150px;">
              </body>
            </html>
            """.format(
                bodyStyle,
                greetStyle,
                jobSeeker.get("firstName", ""),
                jobSeeker.get("lastName", "Someone"),
                title,
                contentStyle,
                messageStyle,
                message,
                str(jobSeekerId),
                jobSeeker.get("email", ""),
                jobSeeker.get("email", ""),
            )
            # =============================================insert link of job seekers profile=========================
            # Record the MIME types of both parts - text/plain and text/html.
            part1 = MIMEText(text, "plain")
            part2 = MIMEText(html, "html")

            # Attach parts into message container.
            # According to RFC 2046, the last part of a multipart message, in this case
            # the HTML message, is best and preferred.
            msg.attach(part1)
            msg.attach(part2)

            image = MIMEImage(img_data, name=os.path.basename("app/static/images/logo.png"))
            msg.attach(image)

            s = smtplib.SMTP("smtp.gmail.com:587")
            username = "******"
            password = "******"
            s.ehlo()
            s.starttls()
            s.ehlo()
            s.login(username, password)
            s.sendmail(From, To, msg.as_string())
            s.quit()

        else:
            print("Nothing")
    return jsonify(result=modal)
Exemple #27
0
    def validate(self):
        rv = Form.validate(self)
        if not rv:
            message = ''
            for fieldName, errorMessages in self.errors.items():
                for err in errorMessages:
                    message = message + fieldName + ': ' + err + '\n'
            flash(message, 'error')
            return False

        user = savvy_collection.find_one({EMAIL: self.email.data.rstrip()})
        if user:
            # send email with new password to this address
            link = "http://savvyhire.herokuapp.com/changepassword"

            img_data = open('app/static/images/logo.png', 'rb').read()
            msg = MIMEMultipart('alternative')
            msg['Subject'] = 'Password recovery!'
            msg['From'] = '*****@*****.**'
            msg['To'] = user['email']
            From = '*****@*****.**'
            To = user['email']

            text = """Hi {},\nYou have forgotten your password, but that's alright!\nClick this link to change your password:\n"{}/{}/{}"\nBest,\nTeam SavvyHire
            """.format(user.get('firstName'), link, user.get('email'),
                       user.get('password'))

            bodyStyle = """
                background: #F3F4F5;
                padding: .71428571rem 1rem;
                box-shadow: none;
                border: 1px solid #D4D4D5;
                border-radius: .28571429rem;
                font-family: Lato,'Helvetica Neue',Arial,Helvetica,sans-serif;
            """
            greetStyle = """
                font-weight: 500;
                font-size: 27px;
            """
            contentStyle = """
                margin-bottom: 10px;
                margin-top: 5px;
                font-weight: normal;
                font-size: 17px;
                line-height: 1.6;
            """
            messageStyle = """
                margin-bottom: 4%;
                line-height: 2;
                display: block;
                background: #FFF;
                border: 1px solid rgba(133, 183, 217,.5);
                padding-top: 3%;
                padding-left: 7%;
                border-radius: 0.285714rem;
            """

            html = """\
            <html>
              <head></head>
              <body style="{}">
                <p><span style="{}">Hi {},<br><br></span>
                   <span style="{}">
                   You have forgotten your password, but that's alright!<br><br>
                   Click this link to change your password:<br><br>
                   <span style="{}"
                   <i>{}/{}/{}</i><br><br>
                   </span>
                   Best,<br>
                   Team SavvyHire<br>
                   </span>
                </p>
                <img src="https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xap1/v/t1.0-9/12552797_946970445338090_4081041973572931633_n.png?oh=3657d0fd2ab010f7b752f825c16070ba&oe=572DAC6A&__gda__=1463629238_96cd9ea3062bfbbb1539e9cdfb18ad25" style="width:150px;">
              </body>
            </html>
            """.format(bodyStyle, greetStyle, user.get('firstName', ''),
                       contentStyle, messageStyle, link, user.get('email'),
                       user.get('password'))

            # Record the MIME types of both parts - text/plain and text/html.
            part1 = MIMEText(text, 'plain')
            part2 = MIMEText(html, 'html')

            # Attach parts into message container.
            # According to RFC 2046, the last part of a multipart message, in this case
            # the HTML message, is best and preferred.
            msg.attach(part1)
            msg.attach(part2)

            image = MIMEImage(
                img_data, name=os.path.basename('app/static/images/logo.png'))
            msg.attach(image)

            s = smtplib.SMTP('smtp.gmail.com:587')
            username = "******"
            password = '******'
            s.ehlo()
            s.starttls()
            s.ehlo()
            s.login(username, password)
            s.sendmail(From, To, msg.as_string())
            s.quit()

            return True
        else:
            flash("{} doesn't exisit in our database".format(self.email.data),
                  'error')
            return False
Exemple #28
0
def applyJobs():
    if request.method == 'POST':
        print(request.form)
        message = request.form['applyJobMsg']
        employerId = request.form['employerId']
        employerId = ObjectId(employerId)
        modal = request.form['modalId']
        jobSeekerId = request.form['jobSeeker']
        jobSeekerId = ObjectId(jobSeekerId)
        title = request.form['title']

        #print(modal)
        jobSeeker = savvy_collection.find_one({'_id': jobSeekerId})
        user = savvy_collection.find_one({'_id': employerId})

        print(employerId)
        print(request.form)

        if user:
            # Send an email
            img_data = open('app/static/images/logo.png', 'rb').read()
            msg = MIMEMultipart('alternative')
            msg['Subject'] = "{} {} applied for your {} position on SavvyHire".format(
                jobSeeker.get('firstName', ''),
                jobSeeker.get('lastName', 'Someone'), title)
            msg['From'] = '*****@*****.**'
            msg['To'] = user['email']
            From = '*****@*****.**'
            To = user['email']

            text = """{} {} applied for your {} job!\nHere's the message:\n"{}"\nBest,\nTeam SavvyHire
            """.format(jobSeeker.get('firstName', ''),
                       jobSeeker.get('lastName', 'Someone'), title, message)

            bodyStyle = """
                background: #F3F4F5;
                padding: .71428571rem 1rem;
                box-shadow: none;
                border: 1px solid #D4D4D5;
                border-radius: .28571429rem;
                font-family: Lato,'Helvetica Neue',Arial,Helvetica,sans-serif;
            """
            greetStyle = """
                font-weight: 500;
                font-size: 27px;
            """
            contentStyle = """
                margin-bottom: 10px;
                margin-top: 5px;
                font-weight: normal;
                font-size: 17px;
                line-height: 1.6;
            """
            messageStyle = """
                margin-bottom: 4%;
                line-height: 2;
                display: block;
                background: #FFF;
                border: 1px solid rgba(133, 183, 217,.5);
                padding: 1%;
                border-radius: 0.285714rem;
                white-space: PRE;
                word-wrap: break-word;
            """

            html = """\
            <html>
              <head></head>
              <body style="{}">
                <p><span style="{}">{} {} applied for your {} job!<br><br></span>
                   <span style="{}">
                   Here's their cover letter:<br><br>
                   <span style="{}"
                   <i>{}</i>
                   </span>
                   Here's the link to their digital cv:<br>
                   http://savvyhire.herokuapp.com/candidate/{}
                   <br><br>
                   Here's the email for you to contact directly: <a href="mailto:{}">{}</a>  <small style="color:rgb(17, 166, 86);">click it!</small>
                   <br><br>
                   Best,<br>
                   Team SavvyHire<br>
                   </span>
                </p>
                <img src="https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xap1/v/t1.0-9/12552797_946970445338090_4081041973572931633_n.png?oh=3657d0fd2ab010f7b752f825c16070ba&oe=572DAC6A&__gda__=1463629238_96cd9ea3062bfbbb1539e9cdfb18ad25" style="width:150px;">
              </body>
            </html>
            """.format(bodyStyle, greetStyle, jobSeeker.get('firstName', ''),
                       jobSeeker.get('lastName', 'Someone'), title,
                       contentStyle, messageStyle, message, str(jobSeekerId),
                       jobSeeker.get('email', ''), jobSeeker.get('email', ''))
            #=============================================insert link of job seekers profile=========================
            # Record the MIME types of both parts - text/plain and text/html.
            part1 = MIMEText(text, 'plain')
            part2 = MIMEText(html, 'html')

            # Attach parts into message container.
            # According to RFC 2046, the last part of a multipart message, in this case
            # the HTML message, is best and preferred.
            msg.attach(part1)
            msg.attach(part2)

            image = MIMEImage(
                img_data, name=os.path.basename('app/static/images/logo.png'))
            msg.attach(image)

            s = smtplib.SMTP('smtp.gmail.com:587')
            username = "******"
            password = '******'
            s.ehlo()
            s.starttls()
            s.ehlo()
            s.login(username, password)
            s.sendmail(From, To, msg.as_string())
            s.quit()

        else:
            print('Nothing')
    return jsonify(result=modal)
Exemple #29
0
 def validate_password(email, password):
     user = savvy_collection.find_one({ EMAIL: email })
     return user[PASSWORD] == password
Exemple #30
0
def connect():
    if request.method == 'POST':
        message = request.form['connectMsg']
        user = request.form['user']
        modal = request.form['modalId']

        #print(modal)
        user = savvy_collection.find_one( {EMAIL: user} )
        if user:
            # Send an email
            img_data = open('app/static/images/logo.png', 'rb').read()
            msg = MIMEMultipart('alternative')
            msg['Subject'] = 'An employer wants you!'
            msg['From'] = '*****@*****.**'
            msg['To'] = user['email']
            From = '*****@*****.**'
            To = user['email']

            text = """Dear {},\nAn employer is interested in your profile on SavvyHire and has a message for you!\nHere's the message:\n"{}"\nBest,\nTeam SavvyHire
            """.format(user.get('firstName'), message)

            bodyStyle = """
                background: #F3F4F5;
                padding: .71428571rem 1rem;
                box-shadow: none;
                border: 1px solid #D4D4D5;
                border-radius: .28571429rem;
                font-family: Lato,'Helvetica Neue',Arial,Helvetica,sans-serif;
            """
            greetStyle = """
                font-weight: 500;
                font-size: 27px;
            """
            contentStyle = """
                margin-bottom: 10px;
                margin-top: 5px;
                font-weight: normal;
                font-size: 17px;
                line-height: 1.6;
            """
            messageStyle = """
                margin-bottom: 4%;
                line-height: 2;
                display: block;
                background: #FFF;
                border: 1px solid rgba(133, 183, 217,.5);
                padding-top: 3%;
                padding-left: 7%;
                border-radius: 0.285714rem;
            """

            html = """\
            <html>
              <head></head>
              <body style="{}">
                <p><span style="{}">Dear {},<br><br></span>
                   <span style="{}">
                   An employer is interested in your profile on SavvyHire and has a message for you!<br><br>
                   Here's the message:<br><br>
                   <span style="{}"
                   <i>{}</i><br><br>
                   </span>
                   Best,<br>
                   Team SavvyHire<br>
                   </span>
                </p>
                <img src="https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xap1/v/t1.0-9/12552797_946970445338090_4081041973572931633_n.png?oh=3657d0fd2ab010f7b752f825c16070ba&oe=572DAC6A&__gda__=1463629238_96cd9ea3062bfbbb1539e9cdfb18ad25" style="width:150px;">
              </body>
            </html>
            """.format(bodyStyle, greetStyle, user.get('firstName'), contentStyle, messageStyle, message)

            # Record the MIME types of both parts - text/plain and text/html.
            part1 = MIMEText(text, 'plain')
            part2 = MIMEText(html, 'html')

            # Attach parts into message container.
            # According to RFC 2046, the last part of a multipart message, in this case
            # the HTML message, is best and preferred.
            msg.attach(part1)
            msg.attach(part2)

            image = MIMEImage(img_data, name=os.path.basename('app/static/images/logo.png'))
            msg.attach(image)

            s = smtplib.SMTP('smtp.gmail.com:587')
            username = "******"
            password = '******'
            s.ehlo()
            s.starttls()
            s.ehlo()
            s.login(username, password)
            s.sendmail(From, To, msg.as_string())
            s.quit()

        else:
            print('Nothing')
    return jsonify(result=modal)
Exemple #31
0
def connect():
    if request.method == 'POST':
        message = request.form['connectMsg']
        user = request.form['user']
        modal = request.form['modalId']

        #print(modal)
        user = savvy_collection.find_one({EMAIL: user})
        if user:
            # Send an email
            img_data = open('app/static/images/logo.png', 'rb').read()
            msg = MIMEMultipart('alternative')
            msg['Subject'] = 'An employer wants you!'
            msg['From'] = '*****@*****.**'
            msg['To'] = user['email']
            From = '*****@*****.**'
            To = user['email']

            text = """Dear {},\nAn employer is interested in your profile on SavvyHire and has a message for you!\nHere's the message:\n"{}"\nBest,\nTeam SavvyHire
            """.format(user.get('firstName'), message)

            bodyStyle = """
                background: #F3F4F5;
                padding: .71428571rem 1rem;
                box-shadow: none;
                border: 1px solid #D4D4D5;
                border-radius: .28571429rem;
                font-family: Lato,'Helvetica Neue',Arial,Helvetica,sans-serif;
            """
            greetStyle = """
                font-weight: 500;
                font-size: 27px;
            """
            contentStyle = """
                margin-bottom: 10px;
                margin-top: 5px;
                font-weight: normal;
                font-size: 17px;
                line-height: 1.6;
            """
            messageStyle = """
                margin-bottom: 4%;
                line-height: 2;
                display: block;
                background: #FFF;
                border: 1px solid rgba(133, 183, 217,.5);
                padding-top: 3%;
                padding-left: 7%;
                border-radius: 0.285714rem;
            """

            html = """\
            <html>
              <head></head>
              <body style="{}">
                <p><span style="{}">Dear {},<br><br></span>
                   <span style="{}">
                   An employer is interested in your profile on SavvyHire and has a message for you!<br><br>
                   Here's the message:<br><br>
                   <span style="{}"
                   <i>{}</i><br><br>
                   </span>
                   Best,<br>
                   Team SavvyHire<br>
                   </span>
                </p>
                <img src="https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xap1/v/t1.0-9/12552797_946970445338090_4081041973572931633_n.png?oh=3657d0fd2ab010f7b752f825c16070ba&oe=572DAC6A&__gda__=1463629238_96cd9ea3062bfbbb1539e9cdfb18ad25" style="width:150px;">
              </body>
            </html>
            """.format(bodyStyle, greetStyle, user.get('firstName'),
                       contentStyle, messageStyle, message)

            # Record the MIME types of both parts - text/plain and text/html.
            part1 = MIMEText(text, 'plain')
            part2 = MIMEText(html, 'html')

            # Attach parts into message container.
            # According to RFC 2046, the last part of a multipart message, in this case
            # the HTML message, is best and preferred.
            msg.attach(part1)
            msg.attach(part2)

            image = MIMEImage(
                img_data, name=os.path.basename('app/static/images/logo.png'))
            msg.attach(image)

            s = smtplib.SMTP('smtp.gmail.com:587')
            username = "******"
            password = '******'
            s.ehlo()
            s.starttls()
            s.ehlo()
            s.login(username, password)
            s.sendmail(From, To, msg.as_string())
            s.quit()

        else:
            print('Nothing')
    return jsonify(result=modal)
Exemple #32
0
 def validate_password(email, password):
     user = savvy_collection.find_one({EMAIL: email})
     return user[PASSWORD] == password