@@ -173,4 +173,16 @@ frappe.ready(function() { | |||||
} | } | ||||
}); | }); | ||||
{%- endif %} | |||||
{%- endif %} | |||||
{% if google_sign_in is defined -%} | |||||
frappe.ready(function() { | |||||
$(".btn-google").click(function() { | |||||
frappe.call({ | |||||
method: "frappe.templates.pages.login.get_google_auth_url" | |||||
}) | |||||
}) | |||||
}) | |||||
{%- endif -%} |
@@ -20,6 +20,13 @@ | |||||
<button type="button" class="btn btn-lg btn-primary btn-block btn-facebook"> | <button type="button" class="btn btn-lg btn-primary btn-block btn-facebook"> | ||||
{{ _("Login via Facebook") }}</button></p> | {{ _("Login via Facebook") }}</button></p> | ||||
{%- endif -%} | {%- endif -%} | ||||
{%- if google_sign_in is defined %} | |||||
<p class="text-center"> | |||||
<p class="text-muted text-center" style="margin: 10px;">or</p> | |||||
<a href="{{ google_sign_in }}" target="_blank" | |||||
type="button" class="btn btn-lg btn-primary btn-block btn-google"> | |||||
{{ _("Login via Google") }}</a></p> | |||||
{%- endif -%} | |||||
<p class="text-center"> | <p class="text-center"> | ||||
<br><a href="#signup">{{ _("Not a user yet? Sign up") }}</a> | <br><a href="#signup">{{ _("Not a user yet? Sign up") }}</a> | ||||
</p> | </p> | ||||
@@ -2,10 +2,47 @@ | |||||
# MIT License. See license.txt | # MIT License. See license.txt | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe | |||||
import frappe, os | |||||
import httplib2 | |||||
no_cache = True | |||||
def get_context(context): | def get_context(context): | ||||
# get settings from site config | # get settings from site config | ||||
context["title"] = "Login" | context["title"] = "Login" | ||||
if frappe.conf.get("fb_app_id"): | if frappe.conf.get("fb_app_id"): | ||||
return { "fb_app_id": frappe.conf.fb_app_id } | |||||
context.update({ "fb_app_id": frappe.conf.fb_app_id }) | |||||
if os.path.exists(frappe.get_site_path("google_config.json")): | |||||
context.update({ "google_sign_in": get_google_auth_url() }) | |||||
return context | |||||
def get_google_auth_url(): | |||||
from oauth2client.client import flow_from_clientsecrets | |||||
flow = flow_from_clientsecrets(frappe.get_site_path("google_config.json"), | |||||
scope=['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email'], | |||||
redirect_uri='http://localhost:8000/api/method/frappe.templates.pages.login.login_via_google') | |||||
return flow.step1_get_authorize_url() | |||||
@frappe.whitelist(allow_guest=True) | |||||
def login_via_google(code): | |||||
from oauth2client.client import flow_from_clientsecrets | |||||
flow = flow_from_clientsecrets(frappe.get_site_path("google_config.json"), | |||||
scope=['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email'], | |||||
redirect_uri='http://localhost:8000/api/method/frappe.templates.pages.login.login_via_google') | |||||
credentials = flow.step2_exchange(code) | |||||
http = httplib2.Http() | |||||
http = credentials.authorize(http) | |||||
resp, content = http.request('https://www.googleapis.com/oauth2/v2/userinfo', 'GET') | |||||
print content | |||||
@@ -24,7 +24,7 @@ def render(path): | |||||
data = set_content_type(data, path) | data = set_content_type(data, path) | ||||
frappe._response.data = data | frappe._response.data = data | ||||
frappe._response.headers[b"Page Name"] = path.encode("utf-8") | |||||
frappe._response.headers[b"X-Page-Name"] = path.encode("utf-8") | |||||
def render_page(path): | def render_page(path): | ||||
"""get page html""" | """get page html""" | ||||
@@ -40,7 +40,7 @@ def render_page(path): | |||||
if out: | if out: | ||||
if hasattr(frappe, "_response"): | if hasattr(frappe, "_response"): | ||||
frappe._response.headers[b"From Cache"] = True | |||||
frappe._response.headers[b"X-From-Cache"] = True | |||||
return out | return out | ||||
@@ -16,10 +16,8 @@ def sync_statics(): | |||||
time.sleep(2) | time.sleep(2) | ||||
class sync(object): | class sync(object): | ||||
def __init__(self): | |||||
self.synced = [] | |||||
def start(self): | def start(self): | ||||
self.synced = [] | |||||
for app in frappe.get_installed_apps(): | for app in frappe.get_installed_apps(): | ||||
self.sync_for_app(app) | self.sync_for_app(app) | ||||
@@ -1,7 +1,7 @@ | |||||
chardet | chardet | ||||
cssmin | cssmin | ||||
dropbox | dropbox | ||||
google-api-python-client | |||||
oauth2client | |||||
gunicorn | gunicorn | ||||
httplib2 | httplib2 | ||||
jinja2 | jinja2 | ||||