def post(self):
     action = self.request.get('action')
     if action == "submit_application":
         user = ""
         try:
             user_data = json.loads(self.request.get('user_data'))
             user      = populate.create_user(user_data, "Mentor")
             if user=="User already exists":
                 self.log_user_out()
                 message  = json.dumps({"message":"error", "value":user})
                 self.response.write(message)
             else:
                 programUTF  = json.loads(self.request.get('program')) 
                 programJSON = jsonString.convert(programUTF)  
                 program     = populate.create_program(user, programJSON)
                 mail_status = mailhandler.requestMail(user)
                 notifyuser = mailhandler.notificationMail(user)
                 message     = json.dumps({"message":"success", "firstname":user.first_name, "lastname":user.last_name})
                 self.log_user_out()
                 self.response.write(message)
         except:
             populate.delete_user(user)
             self.log_user_out()
             message  = json.dumps({"message":"error", "value":"unknown"})
             self.response.write(message)
    def get(self):
        authorization_code = self.request.get('code')
        state              = self.request.get('state')
        
        try:
            result             = urllib.urlopen('https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code=%s&redirect_uri=%s&client_id=%s&client_secret=%s' %(authorization_code,Redirect_uri_entrepreneur,API_Key,Secret_Key))

            if result.code == 200 and state == State:
                token       = json.loads(result.read())  
                userprofile = urllib.urlopen('https://api.linkedin.com/v1/people/~:(id,first-name,last-name,public-profile-url,location:(name),summary,industry,positions,recommendations-received,skills:(id,skill),educations:(id,school-name,field-of-study,start-date,end-date,degree,activities,notes),twitter-accounts,picture-url,email-address)?format=json&oauth2_access_token=%s' %(token['access_token']))
                userdata    = json.loads(userprofile.read())
                profilepic           = urllib.urlopen('https://api.linkedin.com/v1/people/~/picture-urls::(original)?format=json&oauth2_access_token=%s' %(token['access_token'])) 
                bigPic               = json.loads(profilepic.read())
                userdata["big_pic"]  = bigPic['values'][0]
                user  = populate.create_user(userdata, 'Entrepreneur')
                if user=='User already exists':
                    self.log_user_out()
                    self.render("/duplicate.html")
                else:
                    user_id = user.key().id()
                    self.log_user_in(str(user_id))
                    mail_status = mailhandler.requestMail(user)
                    notifyuser = mailhandler.notificationMail(user)
                    confirmation_msg  = "Your account has been successfully created and is pending approval"
                    self.log_user_out()
                    self.render('/success_entrepreneur.html')
            ########################################### need to send alert to admin for confirmation of new user ####################################################
            else:
                self.redirect("/home")         
        except:
            self.response.write("Something seems to have gone wrong.")
    def post(self):
        action = self.request.get('action')
        if action == "submit_application":
            try:
                user_data = json.loads(self.request.get('user_data'))
                user      = populate.create_user(user_data, "Job Applicant")
                if user=="User already exists":
                    self.log_user_out()
                    message  = json.dumps({"message":"error", "value":user})
                    self.response.write(message)
                else:
                    programUTF  = json.loads(self.request.get('program')) 
                    programJSON = jsonString.convert(programUTF)  
                    program     = populate.create_program(user, programJSON)
                    
                    mail_status = mailhandler.requestMail(user)
                    message     = json.dumps({"message":"success", "firstname":user.first_name, "lastname":user.last_name})
                    self.log_user_out()
                    self.response.write(message)
########################################### need to send alert to admin for confirmation of new user ####################################################
            except:
                self.response.write("Something seems to have gone wrong.")

        else:
            self.redirect('/home')