def __init__(self): ''' init conf object and get searched path :return: ''' # get conf object Setting = setting() Setting._setup() self.searchApp = getattr(Setting._wrapped, 'INSTALLED_APPS')
def __init__(self): ''' read configuration then find installed_APP :return: ''' Setting = setting() Setting._setup() # empty this ... self.modelsList = [] self.install_app = Setting._wrapped.INSTALLED_APPS
def __init__(self): Setting = setting() Setting._setup() self.settingMapper = Setting._wrapped # configuration from setting # get configuration from setting # according to peewee we should form that address # dialect[+driver]://user:password@host/dbname self.DB_HOST = Setting._wrapped.DB_HOST self.DB_USER = Setting._wrapped.DB_USER self.DB_PASSWD = Setting._wrapped.DB_PASSWD self.DB_TYPE = Setting._wrapped.DB_TYPE self.DB_DRIVER = Setting._wrapped.DB_DRIVER self.DB_NAME = Setting._wrapped.DB_NAME
def post(self, *args, **kwargs): username = self.get_argument('username') password = self.get_argument('password') self.username = username self.password = password # make sure bcrypt could encrypt this password if len(password) < 8 or len(password) >= 21: self._reason = '密码应为8-20位' self.write_error(500) else: # auth # rewrite by peewee # queryObj = connectInstance.query(adminUser).filter(adminUser.username == username) # print # connectInstance.query(adminUser).filter_by(username=username).count() # using peewee if admin.select().where(admin.username == username).count(): # username exist aimAdmin = admin.select().where(admin.username == username).get() # auth password if aimAdmin.authPassword(password): # successfully login self.set_secure_cookie('username', username) # URL configuration from tjango.conf import setting from tjango.conf.urls import urlPackage Setting = setting() Setting._setup() urlMapper = urlPackage(Setting._wrapped.ROOT_URLCONF) # check permission # auth permission if not aimAdmin.isStaff: self._reason = '您的账号目前无法访问仪表盘,请联系管理员。' self.write_error(404) # redirect self.redirect( self.reverse_url('tjango.contrib.admin.views.adminManageHandler')) else: self._reason = user_locale.translate('Wrong username or password') self.write_error(404) else: self._reason = user_locale.translate('Wrong username or password') self.write_error(404) args = locals() args.pop('self')
def get_random_string(length=12, allowed_chars='abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'): """ Return a securely generated random string. The default length of 12 with the a-z, A-Z, 0-9 character set returns a 71-bit value. log_2((26+26+10)^12) =~ 71 bits """ if not using_sysrandom: # This is ugly, and a hack, but it makes things better than # the alternative of predictability. This re-seeds the PRNG # using a value that is hard for an attacker to predict, every # time a random string is required. This may change the # properties of the chosen random sequence slightly, but this # is better than absolute predictability. Setting = setting() Setting._setup() random.seed( hashlib.sha256( ('%s%s%s' % (random.getstate(), time.time(), Setting._wrapped.SECRET_KEY)).encode()).digest()) return ''.join(random.choice(allowed_chars) for i in range(length))
def get(self, *args, **kwargs): import psutil import platform # cpu info logicalCPU = psutil.cpu_count(logical=True) physicsCPU = psutil.cpu_count(logical=False) # platform uname (system, node, release, version, machine, processor) = platform.uname() # cpu usage usedCPURate = psutil.cpu_percent(interval=1, percpu=False) # memory info mem = psutil.virtual_memory() # start time startTime = psutil.boot_time() # network statistics network = psutil.net_io_counters(pernic=False) from tjango.conf import setting Setting = setting() Setting._setup() logFileExist = getattr(Setting._wrapped, 'LOGFILE', False) modelsFinder = modelFinder() # a tuple containing three element : app,className,class modelsList = modelsFinder.getInstalledModel() # fill render parameter args = locals() args.pop('self') self.render('templates/contrib/admin/manage.html', **args)