コード例 #1
0
ファイル: index.py プロジェクト: armolee/homework
 def get_users(self):
     """
     显示用户的信息,用户新建、删除、解锁用户时显示用户基本信息
     :return:
     """
     username = my_Common.input_msg("请输入用户名:")
     # 创建一个用户实例
     _deluser = my_clsUsers()
     _deluser.username = username
     # 如果用户名存在,load用户信息成功
     if _deluser.load_user_info():
         # 先显示一下用户的信息
         my_Common.show_message(
             my_template.user_info.format(
                 username=_deluser.username,
                 name=_deluser.name,
                 mobile=_deluser.mobile,
                 role=_deluser.role,
                 isdel="否" if _deluser.isdel == 0 else "是",
                 islocked="否" if _deluser.islocked == 0 else "是",
                 bindcard=_deluser.bindcard), "NOTICE")
         return _deluser
     else:
         my_Common.show_message("用户名不存在!", "ERROR")
         return False
コード例 #2
0
 def logout(self):
     """
     注销当前用户,将系统属性置空
     :return:
     """
     self.islogin = False
     self.bindcard = ""
     self.mobile = ""
     self.name = ""
     self.password = ""
     self.username = ""
     my_Common.show_message("注销成功", "NOTICE")
コード例 #3
0
ファイル: init_DB.py プロジェクト: xiaozhimengmengda/homework
	def init_database(self):
		#获取数据文件列表
		tables = list(my_conf.DATABASE['tables'].values())
		#数据表存放路径
		database = my_conf.DATABASE['dbpath']

		for _table in tables:
			if not os.path.exists(os.path.join(database, '{0}.db'.format(_table))):
				if hasattr(self, 'init_db_{0}'.format(_table)): #反射
					init_func = getattr(init_DB, 'init_db_{0}'.format(_table))
					init_func(self)
				else:
					my_Common.write_error_log(
						"Table create Error...." + os.path.join(database, '{0}.db'.format(_table)))
			else:
				my_Common.show_message(os.path.join(database, '{0}.db'.format(_table),
													'表已经存在,数据初始化已完成'), "INFORMATION")
コード例 #4
0
 def modify_password(self):
     """
     个人中心 - 修改密码
     :return:
     """
     _not_null_flag = False
     try:
         while not _not_null_flag:
             _new_password = input("输入新密码: ").strip()
             _confirm_password = input("再次输入确认密码:").strip()
             if not _new_password or not _confirm_password:
                 my_Common.show_message("密码不能为空,请重新输入!", "ERROR")
                 continue
             if _new_password != _confirm_password:
                 my_Common.show_message("两次输入密码不一致,请重新输入!", "NOTICE")
                 continue
             _not_null_flag = True
         self.password = _new_password
         _password = my_Common.encrypt(self.password)
         self.dict_user[self.username]["password"] = _password
         self.update_user()
         my_Common.show_message("密码修改成功!", "INFORMATIOM")
         return True
     except Exception as e:
         my_Common.write_error_log(e)
         return False
コード例 #5
0
ファイル: clsUsers.py プロジェクト: python-13/homework
    def init_user_info(self):
        """
        创建用户,完善用户资料信息
        需要创建一个新的对象
        :return:
        """
        is_null_flag = True
        while is_null_flag:
            self.username = input("登录用户名(小写字母):").strip().lower()
            if not self.username:
                my_Common.show_message("用户名不能为空", "ERROR")
                continue
            elif self.user_exists:
                my_Common.show_message("该用户名已存在", "ERROR")
                continue
            else:
                is_null_flag = False
                continue

        self.name = my_Common.input_msg("姓名:")
        self.password = my_Common.input_msg("密码:")
        self.mobile = my_Common.input_msg("手机:")
        self.role = my_Common.input_msg("用户权限(user/admin):", ("admin", "user"))
        self.create_user()  #调用创建用户的方法
        my_Common.show_message("用户创建成功!", "NOTICE")
コード例 #6
0
    def modify_user_info(self):
        """
        打印用户信息
        :return: 用户信息字符串
        """
        if self.islocked == 1:
            currstatus = "账户锁定"
        else:
            currstatus = "账户正常"
        frmuser = my_template.user_info.format(
            username=self.username,
            name=self.name,
            mobile=self.mobile,
            bindcard=self.bindcard,
            role=self.role,
            islocked="是" if self.islocked == 1 else "否",
            isdel="是" if self.isdel == 1 else "否"
        )
        # 打印用户信息
        my_Common.show_message(frmuser, "NOTICE")
    
        # 开始修改
        my_Common.show_message("请输入新的资料,若不更新直接回车:", "NOTICE")
        # 三元运算
        new_name = input("姓名({0}); ".format(self.name))
        new_mobile = input("手机({0}): ".format(self.mobile))
        self.name = self.name if len(new_name) == 0 else new_name
        self.mobile = self.mobile if len(new_mobile) == 0 else new_mobile

        # 更新用户资料库变量
        self.dict_user[self.username]["name"] = self.name
        self.dict_user[self.username]["mobile"] = self.mobile

        if self.update_user():
            my_Common.show_message("信息更新成功!", "NOTICE")
        else:
            my_Common.show_message("更新失败,查看日志!", "ERROR")
コード例 #7
0
    def login(self):
        """
        用户登录过程函数,输入用户名和密码后调用内部方法 _user_login进行登录验证
        :return:
        """
        # 如果大于最大尝试次数
        while self.trycount <= my_conf.ERROR_MAX_COUNT:
            if (self.trycount == my_conf.ERROR_MAX_COUNT - 1):
                my_Common.show_message('请注意再输入一次系统将锁定当前用户', "NOTICE")

            self.username = input("用户名: ")
            password = input("密  码: ")
            self.code = '1'  # my_Common.verification_code(1) #随机验证码
            # my_Common.show_message("验证码:{0}".format(self.code), "INFORMATION")
            check_code = '1'  # input("请输入验证码:")

            '''
            验证码
            '''
            if check_code != self.code:
                my_Common.show_message("验证码错误!", "ERROR")
                continue

            '''
            用户名不存在  类中 @property 的方法
            '''
            if not self.user_exists:
                my_Common.show_message("用户名/密码错误!", "ERROR")
                continue

            # 调用用户登录方法进行登录,登录成功后更新对象self
            self._user_login(password, check_code)

            # 用户锁定就直接退出
            if self.islocked:
                my_Common.show_message("该用户已被锁定,请联系系统管理员!", "ERROR")
                self.trycount = 0
                break

            # 登录成功 退出登录
            if self.islogin:
                break
            else:
                my_Common.show_message("用户名密码错误", "NOTICE")

        # else:
        if self.trycount > my_conf.ERROR_MAX_COUNT:
            # 失败后锁定
            self.islocked = 1

            # 更新用户信息
            self.dict_user[self.username]["islocked"] = self.islocked
            self.update_user()
            my_Common.show_message("输入错误次数过多,请联系系统管理员!", "ERROR")
コード例 #8
0
ファイル: index.py プロジェクト: armolee/homework
        # 2 用户登录
        if choose == "1":
            # curruser.
            if (curruser.islogin):
                # 用户已登录
                # 如果用户已经登录,菜单功能2为个人中心,调用另一个菜单模板 index_user_center
                print(
                    my_template.index_user_center.format(
                        curruser.name, today, my_Common.numtochr(weekoftoday)))

                _chooseflag = False
                while not _chooseflag:
                    _choose = input("选择功能:")
                    if _choose not in ("1", "2", "3", "4"):
                        my_Common.show_message("选择正确的功能编号!", "ERROR")
                        continue
                    else:
                        _chooseflag = True
                    if _choose == "4":  # 返回上级菜单
                        quitflag = True
                    if _choose == "3":  # 注销
                        curruser.logout()
                    if _choose == "1":  # 修改密码
                        curruser.modify_password()
                    if _choose == "2":  # 修改 资料
                        curruser.modify_user_info()
            else:
                curruser.login()  # 登录判断
                continue