コード例 #1
0
ファイル: locations.py プロジェクト: p/midge
 def handle_get(self, session_id, values, wfile):
     user = self.application.get_user(session_id)
     if user:
         templates.header(wfile)
         templates.title(wfile, "Home")
         templates.paragraph(
             wfile,
             'You are logged in as '
             '<b>%s</b> with a username of <b>%s</b>.' %
             (user.name, user.username))
         templates.paragraph(
             wfile,
             "You will be automatically logged-out after "
             "any (long) period of inactivity.")
         templates.possible_actions(wfile,
                                    ("logout", "Logout"),
                                    ("modifyuser", "Modify user account"))
         templates.footer(wfile)
     else:
         templates.header(wfile)
         templates.title(wfile, "Home")
         templates.paragraph(
             wfile,
             "Either login with an existing username, "
             "or create a new account if you are a new user.")
         templates.possible_actions(wfile,
                                    ("login", "Login"),
                                    ("adduser",
                                     "Create a new user account"))
         templates.footer(wfile)
コード例 #2
0
ファイル: locations.py プロジェクト: p/midge
 def _add_bug(self, session_id, wfile, post_data):
     new_version = post_data.pop("new_version", None)
     if new_version:
         post_data["version"] = new_version
     new_category = post_data.pop("new_category", None)
     if new_category:
         post_data["category"] = new_category
     new_keyword = post_data.pop("new_keyword", None)
     if new_keyword:
         post_data["keyword"] = new_keyword
     try:
         bug_id = self.application.add_bug(session_id, **post_data)
         templates.title(wfile, "Successfuly added new bug")
         templates.paragraph(
             wfile,
             'You have justed created new bug, number '
             '%s.' % bug_id)
         templates.possible_actions(
             wfile,
             ("/new", "Add another bug"),
             ("/view?bug_id=%s" % bug_id,
              "View the newly created Bug %s" % bug_id),
             ("/home", "Home"))
     except application.InvalidValueException:
         templates.title(wfile, "Failed to add new bug!")
         templates.paragraph(
             wfile,
             'One of the new values you have entered is invalid. '
             'Use the back-button of your browser to correct.')
コード例 #3
0
ファイル: locations.py プロジェクト: p/midge
 def handle_post(self, session_id, values, post_data, wfile):
     next_location = values.pop("next", None) or Home.path
     username = post_data.get("username", None)
     password = post_data.get("password", None)
     if username and password and \
            self.application.login(session_id, username, password):
         path = lib.join_url(next_location, values)
         self.redirect(path)
     else:
         user = self.application.get_user(session_id)
         templates.header(wfile)
         templates.title(wfile, "Login failed!")
         if username:
             templates.paragraph(
                 wfile,
                 "You entered an incorrect password for user of username "
                 "<b>%s</b>." % username)
             templates.paragraph(
                 wfile,
                 "Use the back-button of your browser to try again, "
                 "or click below to request that your password be emailed "
                 "to you.")
             templates.possible_actions(
                 wfile,
                 ("emailpassword?username=%s" % username, 
                  "Email me my password"))
         else:
             templates.paragraph(
                 wfile,
                 "You did not provide a username. "
                 "Use the back-button of your browser to try again.")
         templates.footer(wfile)
コード例 #4
0
ファイル: locations.py プロジェクト: p/midge
 def handle_get(self, session_id, values, wfile):
     if "next" not in values:
         values["next"] = Home.path
     user = self.application.get_user(session_id)
     templates.header(wfile)
     templates.title(wfile, "User login")
     if user:
         templates.paragraph(
             wfile,
             'Note that you are already logged in as '
             '<b>%s</b> with a username of <b>%s</b>.' %
             (user.name, user.username))
         templates.paragraph(
             wfile,
             'To change user, enter a new username and password and click '
             'the "Login" button.')
         templates.login_form(wfile, self.path, self.application.usernames)
     else:
         path = lib.join_url(self.path, values)
         templates.paragraph(
             wfile,
             'If you have not yet created a user account, '
             'do so now.')
         templates.possible_actions(wfile,
                                    ("adduser", "Create new account"))
         templates.login_form(wfile, path, self.application.usernames)
     templates.footer(wfile)
コード例 #5
0
ファイル: locations.py プロジェクト: p/midge
    def handle_post(self, session_id, values, post_data, wfile):
        user = self.application.get_user(session_id)
        
        username = post_data.get("username", None)
        name = post_data.get("name", None)
        email = post_data.get("email", None)
        password = post_data.get("password", None)
        password_again = post_data.get("password_again", None)

        templates.header(wfile)

        if username and name and email and password and password_again:
            if password == password_again:
                try:
                    self.application.create_new_user(username,
                                                     name,
                                                     email,
                                                     password)
                    templates.title(wfile, "New user account created ok")
                    templates.paragraph(
                        wfile,
                        "Continue to the login page to use this account.")
                    templates.possible_actions(wfile,
                                               ("login", "Login"))
                except application.ValueInUseException:
                    templates.title(wfile, "Failed to create user account!")
                    templates.paragraph(
                        wfile,
                        "The username you chose (<b>%s</b>) is already in "
                        "use by another user. " % username +
                        "Use the back-button of your browser and try "
                        "a different Username.")
            else:
                templates.title(wfile, "Failed to create user account!")
                templates.paragraph(
                    wfile,
                    "The passwords you provided do not match. "
                    "Use the back-button of your browser to try again.")
        else:
            templates.title(wfile, "Failed to create user account!")
            templates.paragraph(
                wfile,
                "You must provide the following information:")
            problems = [description
                        for (item, description) in ((username, "Username"),
                                                    (name, "Name"),
                                                    (email, "Email"),
                                                    (password, "Password"),
                                                    (password_again,
                                                     "Password (again)"))
                        if not item]
            templates.bullets(wfile, *problems)
            templates.paragraph(
                wfile,
                "Use the back-button of your browser to try again.")
        templates.footer(wfile)
コード例 #6
0
ファイル: locations.py プロジェクト: p/midge
 def handle_get(self, session_id, values, wfile):
     user = self.application.get_user(session_id)
     if user:
         self.application.logout(session_id)
         self.redirect(Home.path)
     else:
         templates.header(wfile)
         templates.title(wfile, "You were not logged-in!")
         templates.paragraph(
             wfile,
             "If you wish, you can go to the main screen "
             "in order to log in as a new user.")
         templates.possible_actions(wfile, ("home", "Home"))
         templates.footer(wfile)
コード例 #7
0
ファイル: locations.py プロジェクト: p/midge
 def handle_post(self, session_id, values, post_data, wfile):
     name = post_data.get("name", None)
     email = post_data.get("email", None)
     password = post_data.get("password", None)
     new_password = post_data.get("new_password", None)
     new_password_again = post_data.get("new_password_again", None)
     
     user = self.application.get_user(session_id)
     if user:
         if user.authenticate(password):
             if name:
                 user.name = name
             if email:
                 user.email = email
             templates.header(wfile)
             templates.title(wfile, "User account details changed ok")
             if new_password == new_password_again:
                 if new_password:
                     user.password = new_password
                     templates.paragraph(
                         wfile,
                         "Note that you have changed your "
                         "account to use a <em>new password</em>, "
                         "which must be used from now on.")
             elif new_password or new_password_again:
                 templates.paragraph(
                     wfile,
                     "Note that your password has <em>not</em> "
                     "been changed as the two new passwords you "
                     "provided do not match.")
             templates.paragraph(
                 wfile, "Continue to the home page:")
             templates.possible_actions(wfile, ("/home", "Home"))
         else:
             templates.header(wfile)
             templates.title(wfile, "Failed to change account details!")
             templates.paragraph(
                 wfile,
                 "You failed to authenticate yourself by typing an "
                 "incorrect password. Use the "
                 "back-button of your browser to try again.")
         templates.footer(wfile)
     else:
         self.redirect(Login.path, self.path)
コード例 #8
0
ファイル: templates_test.py プロジェクト: p/midge
 def test_possible_actions(self):
     """Check possible actions"""
     wfile = self.get_wfile()
     templates.possible_actions(wfile, [("href1", "label1"),
                               ("href2", "label2")])
     self.assert_(self.is_well_formed(wfile))