summaryrefslogtreecommitdiffstats
path: root/bitbake
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
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')
-rw-r--r--bitbake/lib/toaster/toastergui/templates/newproject.html35
-rwxr-xr-xbitbake/lib/toaster/toastergui/views.py29
2 files changed, 46 insertions, 18 deletions
diff --git a/bitbake/lib/toaster/toastergui/templates/newproject.html b/bitbake/lib/toaster/toastergui/templates/newproject.html
index e5a6551967..ce01800e08 100644
--- a/bitbake/lib/toaster/toastergui/templates/newproject.html
+++ b/bitbake/lib/toaster/toastergui/templates/newproject.html
@@ -6,36 +6,39 @@
6 <div class="span6"> 6 <div class="span6">
7 <div class="page-header"> 7 <div class="page-header">
8 <h1>Create a new project</h1> 8 <h1>Create a new project</h1>
9 </div> 9 </div>
10 <form> 10 <div class="container-fluid">
11 {% for a in alerts %}
12 <div class="alert alert-error row-fluid" role="alert">{{a}}</div>
13 {% endfor %}
14 </div>
15 <form method="POST">{% csrf_token %}
11 <fieldset> 16 <fieldset>
12 <label>Project name <span class="muted">(required)</span></label> 17 <label>Project name <span class="muted">(required)</span></label>
13 <input type="text" class="input-xlarge" required name="projectname"> 18 <input type="text" class="input-xlarge" required name="projectname" value="{{projectname}}">
14 <label class="project-form"> 19 <label class="project-form">
15 Project owner 20 Project owner
16 <i class="icon-question-sign get-help" title="The go-to person for this project"></i> 21 <i class="icon-question-sign get-help" title="The go-to person for this project"></i>
17 </label> 22 </label>
18 <form method="POST"> 23 <input type="text" name="username" value="{{username}}">
19 <input type="text">
20 <label class="project-form">Owner's email</label> 24 <label class="project-form">Owner's email</label>
21 <input type="email" class="input-large" name="email"> 25 <input type="email" class="input-large" name="email" value="{{email}}">
22 <label class="project-form"> 26 <label class="project-form">
23 Yocto Project version 27 Yocto Project version
24 <i class="icon-question-sign get-help" title="This sets the branch for the Yocto Project core layers (meta, meta-yocto and meta-yocto-bsp), and for the layers you use from the OpenEmbedded Metadata Index"></i> 28 <i class="icon-question-sign get-help" title="This sets the branch for the Yocto Project core layers (meta, meta-yocto and meta-yocto-bsp), and for the layers you use from the OpenEmbedded Metadata Index"></i>
25 </label> 29 </label>
26 <select> 30 <select name="projectversion">
27 <option>Yocto Project 1.7 "D?"</option> 31 <option value="1.7" {%if projectversion == "1.7" %}selected{%endif%}>Yocto Project 1.7 "D?"</option>
28 <option>Yocto Project 1.6 "Daisy"</option> 32 <option value="1.6" {%if projectversion == "1.6" %}selected{%endif%}>Yocto Project 1.6 "Daisy"</option>
29 <option>Yocto Project 1.5 "Dora"</option> 33 <option value="1.5" {%if projectversion == "1.5" %}selected{%endif%}>Yocto Project 1.5 "Dora"</option>
30 </select> 34 </select>
31 </form>
32 </fieldset> 35 </fieldset>
33 36
34 <div class="form-actions"> 37 <div class="form-actions">
35 <a href="project-with-targets.html" class="btn btn-primary btn-large">Create project</a> 38 <input type="submit" class="btn btn-primary btn-large" value="Create project"/>
36 </div> 39 </div>
37 </form> 40 </form>
38 </div> 41 </div>
39 </div> 42 </div>
40 </div> 43 </div>
41{% endblock %} 44{% endblock %}
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