예제 #1
0
    def post(self):
        """Deals with submitting the form."""
        # Get information from the post request
        username = self.request.get("username")
        password = self.request.get("password")

        if "guestLogin" in self.request.POST:
            username = "******"
            password = "******"

        user = db.GqlQuery("SELECT * FROM User WHERE username=:username", username=username).get()
        if user:
            # checks if the username and password are valid
            if validation.valid_pw(user.username, password, user.passHash):
                user_id = user.key().id()

                # Makes and adds the cookie
                self.response.headers["Content-Type"] = "text/plain"
                user_id_val = validation.make_secure_val(str(user_id))
                self.response.headers.add_header("Set-Cookie", str("user=%s; Path=/" % user_id_val))
                self.response.headers.add_header(
                    "Set-Cookie", str("is_user_activated=%s; Path=/" % str(user.activated))
                )

                next_url = self.request.get("next")
                self.redirect(next_url if next_url else "/home")
            #                 self.redirect("home")
            else:
                self.write_form(error="Invalid Password", username=username)
        else:
            self.write_form(error="User doesn't exist")
    def post(self):
        user = User.get_by_id(self.getUser())
        if "updatePassword" in self.request.POST:
            password_success, password_error = "", ""
            if validation.valid_pw(user.username,
                                   self.request.get('currentPassword'),
                                   user.passHash):
                new_pass = self.request.get('new_password')
                if new_pass == self.request.get('verifyNewPassword'):
                    user.passHash = validation.make_pw_hash(
                                      user.username, new_pass)
                    user.put()
                    password_success = "Password Changed Successfully!"
                else:
                    password_error = "New passwords are not the same"
            else:
                password_error = "That is not your current password"
            self.render('admin.html',
                        user=user,
                        update_error=password_error,
                        update_success=password_success)

        elif "otherChanges" in self.request.POST:
            user_email = self.request.get('email')
            venmo_email = self.request.get('venmo_email')

            email = validation.edu_email(user_email)
            venmo_email_verify = validation.email(venmo_email)

            email_error, venmo_email_error, update_success, update_error = "", "", "", ""

            if not email:
                email_error = "That's not a valid email."
                user_email = ""
            if venmo_email != "" and venmo_email_verify is None:
                venmo_email_error = "Invalid email. This is an optional field."
                venmo_email = ""

            if email and (venmo_email_error == ""):
                try:
                    user.email = user_email
                    user.venmo_email = venmo_email
                    user.bio = self.request.get('bio')
                    user.put()
                    update_success = "Succesfully Updated!"
                except:
                    update_error = "Could not save changes :("
            self.render('admin.html', 
                        user=user,
                        update_success=update_success,
                        update_error=update_error,
                        email_error=email_error,
                        venmo_email_error=venmo_email_error)