@修改用户密码
(self, args)
| 982 | return public.returnMsg(True, 'DATABASE_GET_SUCCESS', (str(n),)) |
| 983 | |
| 984 | def ResDatabasePassword(self, args): |
| 985 | """ |
| 986 | @修改用户密码 |
| 987 | """ |
| 988 | id = args['id'] |
| 989 | username = args['name'].strip() |
| 990 | newpassword = public.trim(args['password']) |
| 991 | if not newpassword: return public.returnMsg(False, '修改失败,数据库密码不能为空.') |
| 992 | |
| 993 | find = public.M('databases').where("id=? AND LOWER(type)=LOWER('PgSql')", (id,)).field('id,pid,name,username,password,type,accept,ps,addtime,sid').find() |
| 994 | if not find: return public.returnMsg(False, '修改失败,指定数据库不存在.') |
| 995 | |
| 996 | pgsql_obj = self.get_sql_obj_by_sid(find['sid']) |
| 997 | status, err_msg = pgsql_obj.connect() |
| 998 | if status is False: |
| 999 | return public.returnMsg(False, "连接数据库失败!") |
| 1000 | |
| 1001 | data = pgsql_obj.query('SELECT rolname FROM pg_roles;') |
| 1002 | if username not in data: |
| 1003 | # 添加用户 |
| 1004 | result = self.__CreateUsers(find['sid'], username, username, newpassword, "127.0.0.0.1") |
| 1005 | else: |
| 1006 | result = pgsql_obj.execute("""ALTER USER "{}" with password '{}';""".format(username, newpassword)) |
| 1007 | isError = self.IsSqlError(result) |
| 1008 | if isError != None: return isError |
| 1009 | |
| 1010 | # 修改SQLITE |
| 1011 | public.M('databases').where("id=? AND LOWER(type)=LOWER('PgSql')", (id,)).setField('password', newpassword) |
| 1012 | |
| 1013 | public.WriteLog("TYPE_DATABASE", 'DATABASE_PASS_SUCCESS', (find['name'],)) |
| 1014 | return public.returnMsg(True, 'DATABASE_PASS_SUCCESS', (find['name'],)) |
| 1015 | |
| 1016 | def get_root_pwd(self, args): |
| 1017 | """ |
no test coverage detected