summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/views.py
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2014-06-27 15:09:04 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-07-14 14:10:03 +0100
commit9cfa66bd13afd339760209ad9977c67464118c93 (patch)
tree6fdddb8b7eb052204b8cd5a461e15b4e55e0c85b /bitbake/lib/toaster/toastergui/views.py
parentcff19351a8b9d6267177dc548d994e3f28590391 (diff)
downloadpoky-9cfa66bd13afd339760209ad9977c67464118c93.tar.gz
bitbake: toaster: add automated login in new project page
Toaster uses the Django authentication system to assign user accounts to the projects that are being created. In the current implementation, the user accounts are created/authenticated automatically, on the fly, based on the fields specified in the create new project page. (Bitbake rev: a9062d9692525e24e59b5b2bb4dfdef90b41bf2a) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/views.py')
-rwxr-xr-xbitbake/lib/toaster/toastergui/views.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py
index 7dc0108393..89c02d41ab 100755
--- a/bitbake/lib/toaster/toastergui/views.py
+++ b/bitbake/lib/toaster/toastergui/views.py
@@ -1768,17 +1768,42 @@ def managedcontextprocessor(request):
1768# a default "page not available" simple functions for interactive mode 1768# a default "page not available" simple functions for interactive mode
1769if toastermain.settings.MANAGED: 1769if toastermain.settings.MANAGED:
1770 1770
1771 from django.contrib.auth.models import User
1772 from django.contrib.auth import authenticate, login
1773 from django.contrib.auth.decorators import login_required
1774
1775
1771 # new project 1776 # new project
1772 def newproject(request): 1777 def newproject(request):
1773 template = "newproject.html" 1778 template = "newproject.html"
1774 context = {} 1779 context = {
1780 'email': request.user.email if request.user.is_authenticated() else '',
1781 'username': request.user.username if request.user.is_authenticated() else '',
1782 }
1783
1784
1775 if request.method == "GET": 1785 if request.method == "GET":
1776 # render new project page 1786 # render new project page
1777 return render(request, template, context) 1787 return render(request, template, context)
1778 elif request.method == "POST": 1788 elif request.method == "POST":
1779 if request.method: 1789 mandatory_fields = ['projectname', 'email', 'username', 'projectversion']
1790 if reduce( lambda x, y: x and y, map(lambda x: x in request.POST and len(request.POST[x]) > 0, mandatory_fields)):
1791 if not request.user.is_authenticated():
1792 user = authenticate(username = request.POST['username'], password = 'nopass')
1793 if user is None:
1794 user = User.objects.create_user(username = request.POST['username'], email = request.POST['email'], password = "nopass")
1795 raise Exception("User cannot be authed, creating")
1796 user = authenticate(username = request.POST['username'], password = '')
1797 login(request, user)
1798
1780 return redirect(project) 1799 return redirect(project)
1781 else: 1800 else:
1801 alerts = []
1802 # set alerts for missing fields
1803 map(lambda x: alerts.append('Field '+ x + ' not filled in') if not x in request.POST or len(request.POST[x]) == 0 else None, mandatory_fields)
1804 # fill in new page with already submitted values
1805 map(lambda x: context.__setitem__(x, request.POST[x]), mandatory_fields)
1806 context['alerts'] = alerts
1782 return render(request, template, context) 1807 return render(request, template, context)
1783 raise Exception("Invalid HTTP method for this page") 1808 raise Exception("Invalid HTTP method for this page")
1784 1809