Exemplo n.º 1
0
    def get(self):
        from datetime import datetime

        email_address = self.request.get("email_address")
        corporate_email_address = self.request.get("corporate_email_address")
        existing_user = USERS.get(
            email_address,
            USERS.get(
                corporate_email_address,
                {
                    "company": "",
                    "designation": "",
                    "enrollment_fee": 0,
                    "first_name": "",
                    "graduation_year": 0,
                    "last_name": "",
                    "nearest_railway_line": "western",
                    "payment_mode": "",
                    "phone_number": "",
                    "t_shirt_size": "medium",
                },
            ),
        )
        existing_user_json = json.dumps(existing_user)
        logging.info("[existing_user] " + existing_user_json)
        self.response.out.write(existing_user_json)
Exemplo n.º 2
0
 def get(self):
     session_user = self.get_session_user()
     if session_user:
         auth_level = self.is_user_authorized()
         if auth_level == models.AUTH_LEVEL_REGISTERED_USER:
             self.redirect('/account/activate/reminder/')
         elif auth_level == models.AUTH_LEVEL_ACTIVATED_USER:
             self.redirect('/blog')
         values = dict(
             countries=models.COUNTRIES_LIST,
             month_list=models.MONTH_LIST,
             year_list=models.BIRTH_YEAR_LIST,
             phone_types=models.PHONE_TYPES,
             hint_questions=models.HINT_QUESTIONS_TUPLE_MAP,
             t_shirt_sizes=models.T_SHIRT_TYPES_TUPLE_MAP,
             gender_choices=models.GENDER_CHOICES,
             railway_lines=models.RAILWAY_LINES_TUPLE_MAP,
             mils_year_list=models.MILS_YEAR_LIST
         )
         email = session_user.email
         if email:
             existing_user = USERS.get(email, {})
             graduation_year = existing_user.get('graduation_year', models.MILS_YEAR_LIST[0])
             designation = existing_user.get('designation', '')
             company = existing_user.get('company', '')
             t_shirt_size = existing_user.get('t_shirt_size', 'small')
             nearest_railway_line = existing_user.get('nearest_railway_line', 'western')
             values.update({
                 'graduation_year': graduation_year,
                 'company': company,
                 'designation': designation,
                 't_shirt_size': t_shirt_size,
                 'nearest_railway_line': nearest_railway_line,
                 'phone_type': 'mobile',
             })
         values.update(session_user.to_dict())
         response = render_template('signup.html', **values)
         self.response.out.write(response)
     else:
         self.redirect('/')
Exemplo n.º 3
0
    def get(self):
        token = self.request.get('token')
        url = config.RPX_NOW_API_AUTH_URL
        args = {
            'format': 'json',
            'apiKey': config.RPX_NOW_API_AUTH_KEY,
            'token': token,
        }
        api_response = urlfetch.fetch(url=url,
            payload=urllib.urlencode(args),
            method=urlfetch.POST,
            headers={
                'Content-Type': 'application/x-www-form-urlencoded'
            })
        json_dict = json.loads(api_response.content)
        logging.info('>>>>>>>>>>> rpx_handler: ' + api_response.content)

        if json_dict['stat'] == 'ok':
            profile = json_dict['profile']
            name = profile.get('name', {})
            address = profile.get('address', {})

            identifier = profile.get('identifier')
            cached_session_user = memcache.get('rpxnow_' + identifier)
            if cached_session_user:
                session_user = cached_session_user
            else:
                # Handle birthdate.
                birthdate = profile.get('birthday', models.DEFAULT_BIRTHDATE_STRING)
                birthdate_year, birthdate_month, birthdate_day = birthdate_to_tuple(birthdate)
                birthdate = birthdate_to_string(birthdate_year, birthdate_month, birthdate_day)
                email = profile.get('email', '')
                existing_user = USERS.get(email, {})

                session_user = SessionUser(
                    identifier = identifier,
                    username = profile.get('preferredUsername'),
                    nickname = profile.get('displayName', ''),
                    email = email,
                    verified_email = profile.get('verifiedEmail', ''),
                    auth_provider = profile.get('providerName', ''),
                    profile_url = profile.get('url', ''),
                    formatted_name = name.get('formatted', ''),
                    first_name = name.get('givenName', existing_user.get('first_name', '')),
                    last_name = name.get('familyName', existing_user.get('last_name', '')),
                    middle_name = name.get('middleName', ''),
                    prefix = name.get('honorificPrefix', ''),
                    suffix = name.get('honorificSuffix', ''),

                    gender = profile.get('gender', 'male'),
                    phone_number = profile.get('phoneNumber', existing_user.get('phone_number', '')),
                    photo = profile.get('photo', ''),
                    birthdate = birthdate,
                    birthdate_day = birthdate_day,
                    birthdate_month = birthdate_month,
                    birthdate_year = birthdate_year,

                    address_formatted = address.get('formatted', ''),
                    address_state_province = address.get('region', ''),
                    address_street_name = address.get('streetAddress', ''),
                    address_locality = address.get('locality', ''),
                    address_zip_code = address.get('postalCode', ''),
                    address_country = address.get('country', '')
                    )
                if session_user.nickname or session_user.formatted_name:
                    nickname = session_user.nickname if session_user.nickname else session_user.session_formatted_name
                    import re
                    nickname_split = re.compile('[ ._]').split(nickname)
                    if len(nickname_split) == 1:
                        if not session_user.first_name:
                            session_user.first_name = nickname
                    elif len(nickname_split) == 2:
                        if not session_user.first_name:
                            session_user.first_name = nickname_split[0]
                        if not session_user.last_name:
                            session_user.last_name = nickname_split[1]
                    elif len(nickname_split) >= 3:
                        if not session_user.first_name:
                            session_user.first_name = nickname_split[0]
                        if not session_user.middle_name:
                            session_user.middle_name = nickname_split[1]
                        if not session_user.last_name:
                            session_user.last_name = nickname_split[2]
                memcache.set(identifier, session_user, 1800)
            self.log_in(session_user)
            self.redirect('/account')
        else:
            self.redirect('/')