예제 #1
0
파일: loader.py 프로젝트: tinyms/ArchiveX
    def create_root_account(role_id):
        cnn = SessionFactory.new()
        num = cnn.query(func.count(Archives.id)).scalar()
        role_ = cnn.query(Role).get(role_id)
        if num == 0:
            usr = Archives()
            usr.name = u"超级管理员"
            usr.email = "*****@*****.**"
            usr.code = "P00001"
            cnn.add(usr)
            cnn.commit()

            a = Account()
            a.login_name = "root"
            a.login_pwd = Utils.md5("root")
            a.create_time = datetime.now()
            a.enabled = 1
            a.archives_id = usr.id
            cnn.add(a)
            a.roles.append(role_)
            cnn.commit()
예제 #2
0
파일: anonymous.py 프로젝트: tinyms/Matty
    def create(self):
        account_name = self.param("account_name")
        if not account_name:
            return "AccountNameRequired"
        email = self.param("email")
        if not email:
            return "EmailRequired"
        pwd = self.param("pwd")
        if not pwd:
            return "PwdRequired"
        agree = self.param("agree")
        print(agree)
        if not agree:
            return "AgreeRequired"
        re_pwd = self.param("re_pwd")
        if pwd != re_pwd:
            return "PwdNotSame"

        sf = SessionFactory.new()
        num = sf.query(func.count(Account.id)).filter(Account.login_name == account_name).scalar()
        if num > 0:
            return "AccountExists"
        num = sf.query(func.count(Archives.id)).filter(Archives.email == email).scalar()
        if num > 0:
            return "EmailExists"

        #create a person
        length = len(str(sf.query(func.count(Archives.id)).scalar()))
        max_length = AppSettingHelper.get("s_usr_code_fmt_length", "5")
        prefix = AppSettingHelper.get("s_usr_code_prefix", "P")
        if length > Utils.parse_int(max_length):
            max_length = "%s" % (length + 1)
        fmt = prefix + "%0" + max_length + "d"

        p = Archives()
        p.email = email
        p.name = Utils.email_account_name(email)
        p.join_date = Utils.current_datetime()
        sf.add(p)
        sf.flush()
        p.code = fmt % p.id

        u = Account()
        u.login_name = account_name
        u.login_pwd = Utils.md5(pwd)
        u.create_time = Utils.current_datetime()
        u.last_logon_time = Utils.current_datetime()
        u.enabled = 1
        u.archives_id = p.id
        sf.add(u)
        sf.flush()

        default_role_id = Utils.parse_int(AppSettingHelper.get("s_usr_register_default_role_name", 0))
        if default_role_id > 0:
            default_role = sf.query(Role).get(default_role_id)
            if default_role:
                u.roles.append(default_role)

        sf.commit()

        self.request.set_secure_cookie(IRequest.__key_account_id__, "%i" % u.id)
        self.request.set_secure_cookie(IRequest.__key_account_name__, email)
        return "Success"