MobileBlur

Diff
Login

Diff

Differences From Artifact [fc14c29978]:

To Artifact [682968d4ff]:


1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16

17
18
19
20
21
22
23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24













+


-
+







#!/usr/bin/env python
# coding: utf8

"""
   RPX Authentication for web2py
   Developed by Nathan Freeze (Copyright © 2009)
   Email <nathan@freezable.com>
   Modified by Massimo Di Pierro

   This file contains code to allow using RPXNow.com (now Jainrain.com)
   services with web2py
"""

import os
import re
import urllib
from gluon.html import *
from gluon import *
from gluon.tools import fetch
from gluon.storage import Storage
import gluon.contrib.simplejson as json

class RPXAccount(object):

    """
48
49
50
51
52
53
54
55
56



57
58
59
60
61
62




63
64
65
66
67


68
69
70
71
72
73
74
49
50
51
52
53
54
55


56
57
58
59
60




61
62
63
64
65
66
67


68
69
70
71
72
73
74
75
76







-
-
+
+
+


-
-
-
-
+
+
+
+



-
-
+
+







        self.domain = domain
        self.token_url = url
        self.language = language
        self.profile = None
        self.prompt = prompt
        self.on_login_failure = on_login_failure
        self.mappings = Storage()

        self.mappings.Facebook = lambda profile:\
        
        dn = {'givenName':'','familyName':''}
        self.mappings.Facebook = lambda profile, dn=dn:\
            dict(registration_id = profile.get("identifier",""),
                 username = profile.get("preferredUsername",""),
                 email = profile.get("email",""),
                 first_name = profile.get("name","").get("givenName",""),
                 last_name = profile.get("name","").get("familyName",""))
        self.mappings.Google = lambda profile:\
                 email = profile.get("email",""),                 
                 first_name = profile.get("name",dn).get("givenName",""),
                 last_name = profile.get("name",dn).get("familyName",""))
        self.mappings.Google = lambda profile, dn=dn:\
            dict(registration_id=profile.get("identifier",""),
                 username=profile.get("preferredUsername",""),
                 email=profile.get("email",""),
                 first_name=profile.get("name","").get("givenName",""),
                 last_name=profile.get("name","").get("familyName",""))
                 first_name=profile.get("name",dn).get("givenName",""),
                 last_name=profile.get("name",dn).get("familyName",""))
        self.mappings.default = lambda profile:\
            dict(registration_id=profile.get("identifier",""),
                 username=profile.get("preferredUsername",""),
                 email=profile.get("email",""),
                 first_name=profile.get("preferredUsername",""),
                 last_name='')

107
108
109
110
111
112
113












109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127







+
+
+
+
+
+
+
+
+
+
+
+
                          SCRIPT("RPXNOW.overlay = true;",
                                 "RPXNOW.language_preference = '%s';" % self.language,
                                 "RPXNOW.realm = '%s';" % self.domain,
                                 "RPXNOW.token_url = '%s';" % self.token_url,
                                 "RPXNOW.show();",
                                 _type="text/javascript"))
        return rpxform

def use_janrain(auth,filename='private/janrain.key',**kwargs):
    path = os.path.join(current.request.folder,filename)
    if os.path.exists(path):
        request = current.request
        domain,key = open(path,'r').read().strip().split(':')
        host = current.request.env.http_host
        url = "http://%s/%s/default/user/login" % (host,request.application)
        auth.settings.actions_disabled = \
            ['register','change_password','request_reset_password']
        auth.settings.login_form = RPXAccount(
            request, api_key=key,domain=domain, url = url,**kwargs)