Attachment 'moin-1.8_destroysession.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - destroysession script
4
5 @copyright: 2009 MoinMoin:ReimarBauer
6 @license: GNU GPL, see COPYING for details.
7 """
8 import os
9 from MoinMoin import caching, user
10 from MoinMoin.script import MoinScript
11
12
13 class PluginScript(MoinScript):
14 """\
15 Purpose:
16 ========
17 This script allows you to delete all session cookies from a user in
18 data/cache/__common__/session
19
20 You will usually do this after a user request.
21
22 Detailed Instructions:
23 ======================
24 General syntax: moin [options] account destroysession
25
26 [options] usually should be:
27 --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
28
29 [destroysession-options] see below:
30 1. To remove JohnSmith's session cookies. (He has to login at next request):
31 moin ... account destroysession --name JohnSmith
32 """
33
34 def __init__(self, argv, def_values):
35 MoinScript.__init__(self, argv, def_values)
36
37 self.parser.add_option(
38 "--name", metavar="NAME", dest="uname",
39 help="Destroy Sessions for the user with user name NAME."
40 )
41
42 def mainloop(self):
43 if not self.options.uname:
44 self.parser.error("no name given")
45 self.parser.print_help()
46 import sys
47 sys.exit(1)
48
49 self.init_request()
50 request = self.request
51 if self.options.uname:
52 u = user.User(request, None, self.options.uname)
53 if not u.exists():
54 print 'This user "%s" does not exists!' % u.name
55 return
56
57 cachelist = caching.get_cache_list(request, 'session', 'farm')
58 for sid in cachelist:
59 session = caching.CacheEntry(request, 'session', sid, 'farm',
60 use_pickle=True).content()
61 if session["user.id"] == u.id:
62 caching.CacheEntry(request, 'session', sid, 'farm').remove()
63 print 'Session file "%s" deleted!' % sid
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.