Example #1
0
    def logged_in_user(cls):
        user = users.get_current_user()
        if user is None:
            return False, None

        db_user = User.query_user_id(str(user.user_id()))

        if db_user is None:
            db_user = User.record_from_google_user (user)
                    
        return True, db_user
Example #2
0
    def __init__(self, user):

        if user.user_id() is not None:
            self.stored_user = User.query_user_id(str(user.user_id()))
        elif user.email() is not None:
            self.stored_user = User.query_email(user.email())
        elif user.nickname() is not None:
            self.stored_user = User.query_name(user.nickname())
        else:
            self.stored_user = None
            
        if self.stored_user is None:
            self.__create_user_record(user)
Example #3
0
class UserModel:

    def __init__(self, user):

        if user.user_id() is not None:
            self.stored_user = User.query_user_id(str(user.user_id()))
        elif user.email() is not None:
            self.stored_user = User.query_email(user.email())
        elif user.nickname() is not None:
            self.stored_user = User.query_name(user.nickname())
        else:
            self.stored_user = None
            
        if self.stored_user is None:
            self.__create_user_record(user)

    
    def __create_user_record(self, user):

        self.stored_user = User()

        if user.user_id() is None:
            self.stored_user.user_id = uuid4()
        else:
            self.stored_user.user_id = str(user.user_id())

        if user.email() is not None:
            self.stored_user.email = user.email() 
        
        if user.nickname() is not None:
            self.stored_user.name = user.nickname()

        if user.auth_domain() is not None:
            self.stored_user.auth_domain = user.auth_domain()

        self.stored_user.date_joined = datetime.datetime.utcnow()
     
        logging.info("putting " + self.stored_user.user_id)
        self.stored_user.put()

    def name(self):
        return self.stored_user.name
Example #4
0
    def tool_user(cls):
        user = users.get_current_user()

        if user is None:
            return False, None

        db_user = User.query_user_id(str(user.user_id()))
        if db_user is None or db_user.banned or not db_user.has_tool_access:
            return False, db_user

        return True, db_user
Example #5
0
    def get (self):
        
        tool_user, db_user = ADayThere.tool_user ()

        if not tool_user or not ADayThere.admin_user (db_user):
            self.response.status = 401 
            self.response.write ("Unauthorized")
            return

        query = User.query ()
        if 'name' in self.request.GET.keys ():
            name = self.request.GET['name']
            if name != '':
                query = query.filter (User.name == name) 

        if 'email' in self.request.GET.keys ():
            email = self.request.GET['email']
            if email != '':
                query = query.filter (User.email == email)

        if 'user_id' in self.request.GET.keys ():    
            uid = self.request.GET['user_id']
            if uid != '':
                query = query.filter (User.user_id == uid)


        limit = self.request.get ('limit', None)
        if limit is None:
            limit = ProfilesHandler.max_limit

        cursor = ndb.Cursor (urlsafe=self.request.get ('cursor'))

        users, cursor, more = query.fetch_page (int (limit), start_cursor=cursor)

        users_arr = []

        for each in users:
            u = self.__build_user (each)
            users_arr.append (u)

        safe_cursor = ''
        if cursor:
            safe_cursor = cursor.urlsafe ()

        resp_obj = {
            "users": users_arr,
            "cursor": safe_cursor,
            "more": more
        }

        resp = json.dumps (resp_obj)
        self.response.write (resp)
Example #6
0
    def get (self):

        logged_in, db_user = ADayThere.logged_in_user ()

        if not logged_in:
            self.response.status = 401
            return

        name = self.request.get ('name', None)
        if name is None:
            self.response,status = 400
            self.response.write ("Name required")
            return 

        user = User.query_name (name)

        self.response.status = 200
        if user is not None:
            self.response.write ('not available')
        else:
            self.response.write ('available')
Example #7
0
    def __create_user_record(self, user):

        self.stored_user = User()

        if user.user_id() is None:
            self.stored_user.user_id = uuid4()
        else:
            self.stored_user.user_id = str(user.user_id())

        if user.email() is not None:
            self.stored_user.email = user.email() 
        
        if user.nickname() is not None:
            self.stored_user.name = user.nickname()

        if user.auth_domain() is not None:
            self.stored_user.auth_domain = user.auth_domain()

        self.stored_user.date_joined = datetime.datetime.utcnow()
     
        logging.info("putting " + self.stored_user.user_id)
        self.stored_user.put()
Example #8
0
    def post (self):
        
        tool_user, db_user = ADayThere.tool_user ()

        if not tool_user or not ADayThere.admin_user (db_user):
            self.response.status = 401 
            self.response.write ("Unauthorized")
            return

        user = json.loads (self.request.body)
        record = User.query_user_id (user['user_id'])
        
        if 'type' not in self.request.GET.keys ():
            self.response.status = 400
        else:
            tp = self.request.GET['type']
            if tp == 'ban':
                record.banned = user['banned']
                record.put ()
                self.response.status = 200
            else:
                self.response.status = 400
Example #9
0
    def get (self):
        """
            Check and see if the user is logged in through
            google. If so set up logged in view else
            setup not logged in view.
        """


        db_user = None
        navView = None
        logged_in = False
        if self.user is None:
            navView = LoggedOutNavView ()
        else:
            db_user = User.query_user_id (str (self.user.user_id ()))

            if db_user is None:
                db_user = User.record_from_google_user (self.user)

            if db_user.banned:
                navView = LoggedOutNavView ()
            else:
                navView = LoggedInNavView (db_user)
                logged_in = True

            
        adminProfileModal = AdminProfileModal ()
        contributorModal = BecomeAContributorModal ()
        
        sidebar_display = """
                <li id="sidebar_display_menu_item" ng-controller="sidebarDisplayCtrl" style="list-style:none; position:absolute; right:10px; top:5px">
                    <a href ng-show="sidebar_link.map_is_displayed" ng-click="toggle_sidebar ()">
                    {{ sidebar_display.menu_text }}
                    </a>
                </li>
        """

        self.adaythere.open_element ("header", {"id":"page_header"})
        self.adaythere.open_element ("h1", {"id":"page_heading"}, "A Day There")
        self.adaythere.close_element ("h1")
        self.adaythere.open_element ("nav")
        self.adaythere.append_to_element (navView.get ())
        self.adaythere.close_element ("nav")
        self.adaythere.open_element ("div")
        self.adaythere.append_to_element (adminProfileModal.get ())
        self.adaythere.close_element ("div")
        self.adaythere.open_element ("div")
        self.adaythere.append_to_element (contributorModal.get ())
        self.adaythere.close_element ("div")
        self.adaythere.append_to_element (sidebar_display)
        self.adaythere.close_element ("header")

        self.adaythere.open_element ("div", { "ng-controller":"daysSearchCtrl"})
        
        self.adaythere.open_element ("section", { "id":"welcome_to_left" })
        self.adaythere.append_to_element ("""
                    <img src="img/logo.png" width="60%"></img>
                    <p><h1 style="font-style:italic;text-align:center;font-size:large;">Celebrating the joys of place.</h3></p>
                """)
        self.adaythere.close_element ("section")
        
        self.adaythere.open_element ("section", { "id":"welcome_to_right" })
        self.adaythere.append_to_element ("""<div id="google_like_main" style="float:right;"> <div class="g-plusone" data-size="medium" data-annotation="inline" data-width="250"></div></div>""")
        self.adaythere.close_element ("section")

        self.adaythere.open_element ("section", { "id": "daysearch_overlay" })
        day_search = DaySearch ()
        search_form = day_search.get ()
        self.adaythere.append_to_element (search_form)
        self.adaythere.close_element ("section")


        self.adaythere.open_element ("section", { "id":"find_a_day" })

        self.adaythere.append_to_element ("""
                    <img src="img/logo.png" width="30%"></img>
                    <p><h1 style="font-style:italic;text-align:center;font-size:large;">Celebrating the joys of place.</h3></p>
                """)

        self.adaythere.append_to_element (day_search.get_days_display ())
        self.adaythere.close_element ("section")
    
        self.adaythere.close_element ("div")

        self.adaythere.append_to_element (MapTools.map_elements (logged_in).get ())

        self.adaythere.open_element ("div", { "id":"hello_login_popup" })
        self.adaythere.append_to_element ("""
            <h3>Click the link above to login</h3>
            <p>The white bar is a menu bar and the links drop down menus. Login for more functionality"</p>
        """)
        self.adaythere.close_element ("div")
        self.adaythere.open_element ("div", { "id":"hello_search_popup" })
        self.adaythere.append_to_element ("""
            <h3>The search tools</h3>
            <p>The search tools let you find days that have been created. Login to create your own days.</p>
        """)
        self.adaythere.close_element ("div")
        self.adaythere.open_element ("div", { "id":"hello_help_popup" })
        self.adaythere.append_to_element ("""
            <h3>Help</h3>
            <p>Use the help link in the menu. You'll also find these: <a href popover="Welcome to A Day There" popover-trigger="mouseenter"><strong>?</strong></a> 
            in places and if you place your mouse cursor over them some information will popup."</p>
        """)
        self.adaythere.close_element ("div")
        self.adaythere.open_element ("footer", {"id":"page_footer"})
        self.adaythere.open_element ("p", None, "&copy; 2014 SoftSprocket")
        self.adaythere.close_element ("p")
        self.adaythere.close_element ("footer")

        self.response.write (self.adaythere.get ())
Example #10
0
    def __init__ (self, userid):

        self.user = User.query_user_id (userid)