1 from django.conf import settings
2 from django.contrib.auth import logout
3 from django.contrib.auth.forms import PasswordChangeForm
4 from .base import Plugin
5 from ..extdirect import ext_action, ext_method
6 from ..models import UserPreferences
9 @ext_action(name='auth')
12 def index_js_urls(self):
13 return super(Auth, self).index_js_urls + [
14 settings.STATIC_URL + 'gilbert/plugins/auth.js',
19 return super(Auth, self).icon_names + [
27 def whoami(self, request):
29 return user.get_full_name() or user.username
32 def logout(self, request):
37 def get_passwd_form(self, request):
38 return PasswordChangeForm(request.user).as_extdirect()
40 @ext_method(form_handler=True)
41 def save_passwd_form(self, request):
42 form = PasswordChangeForm(request.user, data=request.POST)
47 return False, form.errors
50 def get_preferences(self, request):
51 user_preferences, created = UserPreferences.objects.get_or_create(user=request.user)
53 return user_preferences.preferences
56 def set_preferences(self, request, preferences):
57 user_preferences, created = UserPreferences.objects.get_or_create(user=request.user)
58 user_preferences.preferences = preferences
60 user_preferences.save()
64 def get_preference(self, request, key):
65 preferences = self.get_preferences(request)
66 return preferences.get(key, None)
69 def set_preference(self, request, key, value):
70 preferences = self.get_preferences(request)
71 preferences[key] = value
72 return self.set_preferences(request, preferences)