def complete_opendata_admin_registration(cls, user, first_name, last_name, password, mobile=""):
        """
            Saves the Agency Admin account details.
        """
        user = user.get()
        user.first_name = first_name
        user.last_name = last_name
        user.name = " ".join([first_name, last_name])
        user.mobile_number = mobile
        user.password = hp(user.current_email, password)
        user.previous_passwords = [hp(user.current_email, password)]
        user.role = "OPENDATAADMIN"
        user.status = "APPROVED"
        user.put()

        # if send:
        #     content = {
        #         "token": user.confirmation_token,
        #         "uid": str(user.key.id())
        #     }

        #     send_email(
        #         receiver_name="OPEN DATA ADMIN",
        #         receiver_email=user.current_email,
        #         subject="Open Data Admin Invitation",
        #         content=content,
        #         email_type="invite_opendata_admin")

        return user
Ejemplo n.º 2
0
 def __init__(self, name):
     db = pyodbc.connect(
         r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
         r'DBQ=./BaseStatus.accdb;')
     cursor = db.cursor()
     cursor.execute("select * from BaseStat where EnName = '" + name + "'")
     param_lst = list(cursor)[0]
     self.name = name
     self.level = 50
     self.HP = functions.hp(param_lst[2], 85, self.level)
     self.totalHP = self.HP
     self.Attack = functions.other_state(param_lst[3], 85, self.level, 1)
     self.Defense = functions.other_state(param_lst[4], 85, self.level, 1)
     self.SpAttack = functions.other_state(param_lst[5], 85, self.level, 1)
     self.SpDefence = functions.other_state(param_lst[6], 85, self.level, 1)
     self.Speed = functions.other_state(param_lst[7], 85, self.level, 1)
     self.FrontPic = "asset\\image\\pokemon\\" + name + ".png"
     self.BackPIc = "asset\\image\\pokemon\\" + name + "_b.png"
     self.critical = 0
     self.accuracy = 1.0
     self.evasion = 1.0
     self.atk_mod = 0
     self.def_mod = 0
     self.spatk_mod = 0
     self.spdef_mod = 0
     self.spd_mod = 0
     self.stat = "None"
     self.type = param_lst[8]
     self.acc_mod = 0
     self.eva_mod = 0
     cursor.execute("select Move from Moves1 where EnName = '" + self.name +
                    "'")
     available_moves = list(cursor)[0][0].split(", ")
     shuffle(available_moves)
     self.move_lst = [
         Move(available_moves[0]),
         Move(available_moves[1]),
         Move(available_moves[2]),
         Move(available_moves[3])
     ]
     cursor.close()
     db.close()
Ejemplo n.º 3
0
    def post(self):
        """
            Handles the /login endpoint.
            Logs in users.
        """
        if self.POST("email") and self.POST("password"):
            url = "/login"
            redirect = None
            email = self.POST("email").strip().lower()
            query = User.query()
            query = query.filter(User.current_email == email)
            user = query.get()

            if self.POST("redirect"):
                redirect = urllib.quote(self.POST("redirect"))
                url += "?redirect=" + str(redirect)

            if not user:
                error = "Invalid email or password."
                error_message(self, error)
                self.redirect(url)
                return

            if user.hashed_password:
                if not user.verify_password(self.POST("password")):
                    error = "Invalid email or password."
                    error_message(self, error)
                    self.redirect(url)
                    return
            else:
                password = hp(email=email, password=self.POST("password"))
                if user.password != password:
                    error = "Invalid email or password."
                    error_message(self, error)
                    self.redirect(url)
                    return
                else:
                    user.hashed_password = user.hash_password(
                        self.POST("password"))
                    user.put()

            if user.status == "PENDING":
                error = "Your account has not been verified. "
                error += "Please verify your account by opening the "
                error += "verification email we sent you. "
                error_message(self, error)
                self.redirect(url)
                return

            if user.status == "DISABLED":
                error = "Your account has been disabled. "
                error += "Please contact the Geostore Admin."
                error_message(self, error)
                self.redirect(url)
                return

            if user.role in ["AGENCYADMIN", "USER"]:
                if user.status == "VERIFIED":
                    error = "Your account is still pending approval. "
                    error += "Once your account is approved, you will be able "
                    error += "to login. You will receive an email once your "
                    error += "account is approved."
                    error_message(self, error)
                    self.redirect(url)
                    return

                if user.status == "DISAPPROVED":
                    error = "Your account has been disapproved. "
                    error += "Please contact the Geostore Admin."
                    error_message(self, error)
                    self.redirect(url)
                    return

            user.csrf_token = generate_token()
            session = SessionHandler(user)
            session.login()
            code = session.generate_login_code()
            if self.POST("redirect"):
                self.redirect(urllib.unquote(str(self.POST("redirect"))))
            else:
                self.redirect("/dashboard")
            return

        error = "Please enter your email and password."
        error_message(self, error)
        self.redirect("/login")
    def create_new_user(
        cls,
        first_name,
        last_name,
        password,
        email,
        role="USER",
        department="",
        agency="",
        region="",
        operating_unit="",
        uacs="",
        middle_name="",
        mobile="",
        designation="",
        salutation="",
        send=True,
    ):
        """
            Creates a new user.
        """
        user = cls()
        user.salutation = salutation
        user.first_name = first_name
        user.last_name = last_name
        user.middle_name = middle_name or ""
        user.name = " ".join([first_name, middle_name or "", last_name])
        user.mobile_number = mobile
        user.original_email = email
        user.current_email = email
        user.email_list = [email]
        user.password = hp(email, password)
        user.previous_passwords = [hp(email, password)]
        # user.department = department
        # user.position = position
        user.confirmation_token = generate_token()

        if uacs:
            user.permissions = ["->".join(["UACS_ID", uacs])]

        if role:
            user.role = role.upper()

        if designation:
            user.designation = designation.upper()

        user.department = department
        user.agency = agency
        user.region = region
        user.operating_unit = operating_unit
        user.uacs = uacs

        user.put()

        if send:
            content = {"token": user.confirmation_token, "uid": str(user.key.id())}

            send_email(
                receiver_name=user.first_name,
                receiver_email=user.current_email,
                subject="Email Verfication",
                content=content,
                email_type="verify",
            )

        return user