Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certificate authority sign up #40

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 32 additions & 21 deletions src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from rq import Queue, use_connection
from validate_email import validate_email

from flask import request
from flask import request, render_template

try:
from collections import OrderedDict as odict
Expand Down Expand Up @@ -139,6 +139,11 @@ def send_mail(to_addresses, subject=None, body=None, mail_type=None,
subject = 'Thanks for Joining the Jupo Waiting List'
template = app.CURRENT_APP.jinja_env.get_template('email/thanks.html')
body = template.render()

elif mail_type == 'mail_verify':
subject = 'E-mail verification for the JUPO'
template = app.CURRENT_APP.jinja_env.get_template('email/verification.html')
body = template.render(domain=domain, **kwargs)

elif mail_type == 'invite':
if kwargs.get('group_name'):
Expand Down Expand Up @@ -172,7 +177,9 @@ def send_mail(to_addresses, subject=None, body=None, mail_type=None,
subject = '%s shared a post with you' % user.name
template = app.CURRENT_APP.jinja_env.get_template('email/new_post.html')
body = template.render(domain=domain, email=to_addresses, user=user, post=post)




elif mail_type == 'new_comment':
user = get_user_info(user_id, db_name=db_name)
post = Feed(post, db_name=db_name)
Expand Down Expand Up @@ -220,7 +227,7 @@ def send_mail(to_addresses, subject=None, body=None, mail_type=None,
msg['Reply-To'] = Header(reply_to, "utf-8")

MAIL = SMTP(settings.SMTP_HOST, settings.SMTP_PORT)

# MAIL = SMTP('54.249.244.48', settings.SMTP_PORT)
if settings.SMTP_USE_TLS is True:
MAIL.starttls()

Expand Down Expand Up @@ -1127,11 +1134,13 @@ def sign_in_with_twitter():
def sign_up(email, password, name, user_agent=None, remote_addr=None):
db_name = get_database_name()
db = DATABASE[db_name]
hostname = db_name.replace('_','.')

email = email.strip().lower()
name = name.strip()
raw_password = password


# Validation
if validate_email(email) is False:
return False
Expand Down Expand Up @@ -1188,22 +1197,16 @@ def sign_up(email, password, name, user_agent=None, remote_addr=None):
None, None,
db_name=db_name)


#TODO: sua lai phan xac thuc
user_id = get_user_id(session_id)
if not user_id:
return False
random_string = settings.EMAIL_CERTIFICATE_KEY
key = hashlib.md5(str(user_id) + random_string).hexdigest()
send_mail_queue.enqueue(send_mail, email, mail_type='mail_verify', key=key,
name=name, id=user_id)


# subject = 'E-mail verification for the 5works Public Beta'
# body = render_template('email/verification.html',
# name=name, domain='jupo.comm', token=token)
# send_mail(email, subject, body)

# init some data
# new_reminder(session_id, 'Find some contacts')
# new_reminder(session_id, 'Upload a profile picture (hover your name at the top right corner, click "Change Profile Picture" in drop down menu)')
# new_reminder(session_id, 'Hover over me and click anywhere on this line to check me off as done')

# add user to "Welcome to 5works" group
# db.owner.update({'_id': 340916998231818241},
# {'$addToSet':{'members': info['_id']}})

return session_id

def sign_out(session_id, db_name=None):
Expand Down Expand Up @@ -1256,9 +1259,17 @@ def reset_password(user_id, new_password):
return True


def verify(token):
pass

def verify(key, user_id):
string_buffer = settings.EMAIL_CERTIFICATE_KEY
key_local = hashlib.md5(str(user_id) + string_buffer).hexdigest()
if key == key_local:
db_name = get_database_name()
db = DATABASE[db_name]
db.owner.update({'_id': long(user_id)},
{'$set': {'verified': True}})
cache.delete('%s:info' % user_id)
return True

def new_verify_token(email):
pass

Expand Down
41 changes: 33 additions & 8 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@
from lib import cache
from lib.img_utils import zoom
from lib.json_util import default as BSON
from validate_email import validate_email


from helpers import extensions
from helpers.decorators import *
from helpers.converters import *

import os
import hashlib
import logging
import requests
import traceback
Expand Down Expand Up @@ -630,7 +633,6 @@ def jobs():
@app.route("/<any(sign_in, sign_up, sign_out, forgot_password, reset_password):action>", methods=["GET", "OPTIONS", "POST"])
def authentication(action=None):
hostname = request.headers.get('Host')

db_name = hostname.replace('.', '_')

primary_domain = '.'.join(settings.PRIMARY_DOMAIN.rsplit('.', 2)[-2:])
Expand Down Expand Up @@ -740,8 +742,10 @@ def authentication(action=None):
alerts['email'] = '"%s" is already in use.' % email
if len(password) < 6:
alerts['password'] = 'Your password must be at least 6 characters long.'



if validate_email(email) is False:
alerts['email'] = 'Type email "%s" is not exact' % email

if alerts.keys():
resp = Response(render_template('sign_up.html',
alerts=alerts,
Expand Down Expand Up @@ -774,6 +778,7 @@ def authentication(action=None):
else:
return redirect('/everyone?getting_started=1')
else:

return redirect('/')

elif request.path.endswith('sign_out'):
Expand Down Expand Up @@ -1038,8 +1043,30 @@ def facebook_authorized(resp):
def get_facebook_token():
return session.get('facebook_access_token')


@app.route('/verify/<key>/<user_id>', methods=['GET'])
def verify(key=None, user_id=None):
if key and user_id and request.path.startswith('/verify'):
info_verify = api.verify(key, user_id)
if info_verify == True:
return redirect('/')


@app.route('/send_mail_verify/<user_id>', methods=['GET'])
@login_required
@line_profile
def send_mail_verify(user_id=None):
hostname = request.headers.get('Host')
if user_id:
owner = api.get_owner_info_from_uuid(user_id)
if owner:
name = owner.name
string_buffer = settings.EMAIL_CERTIFICATE_KEY
key = hashlib.md5(str(user_id) + string_buffer).hexdigest()
email = owner.email
api.send_mail_queue.enqueue(api.send_mail, email, mail_type='mail_verify', key=key,
name=name, id=user_id)
return redirect('/')

@app.route('/reminders', methods=['GET', 'OPTIONS', 'POST'])
@app.route('/reminder/new', methods=["POST"])
@app.route('/reminder/<int:reminder_id>/check', methods=["POST"])
Expand Down Expand Up @@ -2310,9 +2337,7 @@ def news_feed(page=1):
include_archived_posts=False)
category = None


owner = api.get_user_info(user_id)

if request.method == "OPTIONS":
if page > 1:
posts = []
Expand Down Expand Up @@ -3215,7 +3240,7 @@ def run_app(debug=False):



server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8888), app)
server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 9000), app)
try:
print 'Serving HTTP on 0.0.0.0 port 8888...'
server.start()
Expand All @@ -3225,7 +3250,7 @@ def run_app(debug=False):


if __name__ == "__main__":
run_app(debug=True)
run_app(debug=False)



Expand Down
5 changes: 5 additions & 0 deletions src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ def email(self):
if email_addr and '@' in email_addr:
return email_addr

@property
def verified(self):
return self.info.get('verified','')


@property
def email_name(self):
if '@' in self.email:
Expand Down
7 changes: 6 additions & 1 deletion src/settings.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = '<replace with a secret key>'

EMAIL_CERTIFICATE_KEY = 'u5o7z8o9o5r6trm1l80n'

DEBUG = False


Expand Down Expand Up @@ -66,4 +68,7 @@
FACEBOOK_APP_SECRET = None


SENTRY_DSN = 'http://021f15179a8c48dc9a93183b9ce84f5f:[email protected]/3'
# SENTRY_DSN = 'http://021f15179a8c48dc9a93183b9ce84f5f:[email protected]/3'
SENTRY_DSN = 'http://9faa594b71b9432984c98a225fef555e:[email protected]/4'


5 changes: 3 additions & 2 deletions src/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
{% block welcome %}{% endblock %}
{% block main %}
<div id="main">
{% block left_sidebar %}{% endblock %}
{% block body %}{% endblock %}

Expand All @@ -80,7 +80,8 @@
<span>Processing...</span>
</div>




<div id='error' class='hidden' onclick='$(this).hide();'>
<span>
<span class='fontsize-12px'>We're sorry. An unexpected error was encountered.</span><br>
Expand Down
13 changes: 7 additions & 6 deletions src/templates/email/verification.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Hi, {{ name }}

Thanks for signing up for 5-works. Just follow this link to verify your email address and start using 5-works.com

http://{{ domain }}/verify/{{ token }}
<p>Thanks for signing up for JUPO.
Just follow this link to verify your email address and start using {{ domain }}</p>

--
Best Regards,
The 5-works Team
<p>http://{{ domain }}/verify/{{ key }}/{{ id }} </p>
<p>
Best Regards,
The JUPO Team
</p>
10 changes: 10 additions & 0 deletions src/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@
</div>
</div>

{% if owner.verified != True %}
<div id='error'>
<span>
<span class='fontsize-12px'>JUPO send a email to your inbox. Please verify your accout then F5</span><br>
<a href="http://{{ domain }}/send_mail_verify/{{ owner.id }}">Click here to send mail certificate again !</a>
</span>
</div>
{% endif %}


<div id='overlay'></div>
<div id="body">
{% if view == 'new-group' %}
Expand Down