1 # -*- coding: utf-8 -*-
3 # portal/views.py: views for the portal application
4 # This file is part of the Manifold project.
7 # Jordan Augé <jordan.auge@lip6.fr>
8 # Copyright 2013, UPMC Sorbonne Universités / LIP6
10 # This program is free software; you can redistribute it and/or modify it under
11 # the terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 3, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful, but WITHOUT
15 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 # You should have received a copy of the GNU General Public License along with
20 # this program; see the file COPYING. If not, write to the Free Software
21 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 from django.shortcuts import render
24 from portal.forms import UserRegisterForm, SliceRequestForm
26 def user_register(request):
27 if request.method == 'POST':
28 form = UserRegisterForm(request.POST)
30 first_name = form.cleaned_data['first_name']
31 last_name = form.cleaned_data['last_name']
32 email = form.cleaned_data['email']
33 password = form.cleaned_data['password']
34 password2 = form.cleaned_data['password2']
35 keypair = form.cleaned_data['keypair']
36 ## Ici nous pouvons traiter les données du formulaire
37 #sujet = form.cleaned_data['sujet']
38 #message = form.cleaned_data['message']
39 #envoyeur = form.cleaned_data['envoyeur']
40 #renvoi = form.cleaned_data['renvoi']
41 ## Nous pourrions ici envoyer l'e-mail grâce aux données que nous venons de récupérer
44 form = UserRegisterForm()
45 return render(request, 'user_register.html', locals())
47 def user_validate(request):
50 def slice_request(request):
51 if request.method == 'POST':
52 form = SliceRequestForm(request.POST)
54 slice_name = form.cleaned_data['slice_name']
56 form = SliceRequestForm()
57 return render(request, 'slice_request.html', locals())
59 def slice_validate(request):
62 # DEPRECATED #from portal.portalpage import PortalPage
63 # DEPRECATED #from plugins.wizard import Wizard
64 # DEPRECATED #from plugins.form import CreateForm
65 # DEPRECATED #from plugins.raw.raw import Raw # XXX
67 # DEPRECATED #from myslice.viewutils import the_user
69 # DEPRECATED #from django.template.loader import render_to_string
70 # DEPRECATED #from django.template import RequestContext
71 # DEPRECATED #from django.views import generic
73 # DEPRECATED #from django.contrib.formtools.wizard.views import NamedUrlSessionWizardView
74 # DEPRECATED ##from django.core.files.storage import FileSystemStorage
75 # DEPRECATED #from django.core.files.storage import default_storage
77 # DEPRECATED ##class MerlinWizard(NamedUrlSessionWizardView):
82 # DEPRECATED ## @classonlymethod
83 # DEPRECATED ## def as_view(cls, *args, **kwargs):
84 # DEPRECATED ## kwargs.update({
85 # DEPRECATED ## 'form_list': [
86 # DEPRECATED ## NameForm,
87 # DEPRECATED ## QuestForm,
88 # DEPRECATED ## ColorForm,
90 # DEPRECATED ## 'url_name': 'merlin_wizard'
92 # DEPRECATED ## return super(MerlinWizard, cls).as_view(*args, **kwargs)
94 # DEPRECATED #class UserRegisterWizardView(NamedUrlSessionWizardView):
95 # DEPRECATED ##class UserRegisterWizardView(LoginRequiredMixin, NamedUrlSessionWizardView):
96 # DEPRECATED # # Notice that I specify a file storage instance. If you don't specify this,
97 # DEPRECATED # # and you need to support FileField or ImageField in your forms, you'll get
98 # DEPRECATED # # errors from Django. This is something else I think could be handled by
99 # DEPRECATED # # the views better. Seems to me that it should just use whatever the
100 # DEPRECATED # # default/specified storage is for the rest of your project/application.
101 # DEPRECATED # file_storage = default_storage # FileSystemStorage()
102 # DEPRECATED # template_name = "register_user_wizard.html"
104 # DEPRECATED # def done(self, form_list, **kwargs):
105 # DEPRECATED # step1_form = form_list[0]
106 # DEPRECATED # step2_form = form_list[1]
108 # DEPRECATED # productext = self.create_product(product_form)
109 # DEPRECATED # shippings = self.create_shippings(productext, shipping_forms)
110 # DEPRECATED # images = self.create_images(productext, image_forms)
112 # DEPRECATED # if all([productext, shippings, images]):
113 # DEPRECATED # del self.request.session["wizard_product_wizard_view"]
115 # DEPRECATED # messages.success(self.request,
116 # DEPRECATED # _("Your product has been created."))
117 # DEPRECATED # return HttpResponseRedirect(self.get_success_url(productext))
119 # DEPRECATED # messages.error(self.request, _("Something went wrong creating your "
120 # DEPRECATED # "product. Please try again or contact support."))
121 # DEPRECATED # return HttpResponseRedirect(reverse("register_wizard"))
123 # DEPRECATED # #def get_form_kwargs(self, step):
124 # DEPRECATED # # if step == "product":
125 # DEPRECATED # # return {"user": self.request.user}
126 # DEPRECATED # # return {}
128 # DEPRECATED ## The portal should hook the slice and user creation pages
130 # DEPRECATED #def register_user(request):
132 # DEPRECATED # if request.method == 'POST':
133 # DEPRECATED # form = UserRegisterForm(request.POST) # Nous reprenons les données
134 # DEPRECATED # if form.is_valid():
135 # DEPRECATED # first_name = form.cleaned_data['first_name']
136 # DEPRECATED # last_name = form.cleaned_data['last_name']
137 # DEPRECATED # email = form.cleaned_data['email']
138 # DEPRECATED # password = form.cleaned_data['password']
139 # DEPRECATED # password2 = form.cleaned_data['password2']
140 # DEPRECATED # keypair = form.cleaned_data['keypair']
141 # DEPRECATED # ## Ici nous pouvons traiter les données du formulaire
142 # DEPRECATED # #sujet = form.cleaned_data['sujet']
143 # DEPRECATED # #message = form.cleaned_data['message']
144 # DEPRECATED # #envoyeur = form.cleaned_data['envoyeur']
145 # DEPRECATED # #renvoi = form.cleaned_data['renvoi']
146 # DEPRECATED # ## Nous pourrions ici envoyer l'e-mail grâce aux données que nous venons de récupérer
147 # DEPRECATED # #envoi = True
149 # DEPRECATED # form = UserRegisterForm()
150 # DEPRECATED # return render(request, 'register_user.html', locals())
152 # DEPRECATED #def index(request):
154 # DEPRECATED # WIZARD_TITLE = 'User registration'
155 # DEPRECATED # STEP1_TITLE = 'Enter your details'
156 # DEPRECATED # STEP2_TITLE = 'Select your institution'
157 # DEPRECATED # STEP3_TITLE = 'Authentication'
158 # DEPRECATED # STEP4_TITLE = 'Request a slice (optional)'
159 # DEPRECATED # STEP5_TITLE = 'Waiting for validation'
160 # DEPRECATED # STEP6_TITLE = 'Account validated'
162 # DEPRECATED # STEP0 = render_to_string('account_validated.html', context_instance=RequestContext(request))
163 # DEPRECATED # STEP2_HTML = """
164 # DEPRECATED # coucou
166 # DEPRECATED # STEP4 = """
169 # DEPRECATED # STEP5 = render_to_string('account_validated.html', context_instance=RequestContext(request))
171 # DEPRECATED # p = PortalPage(request)
173 # DEPRECATED # # This is redundant with the Wizard title
174 # DEPRECATED # p << "<h3>User registration</h3>"
176 # DEPRECATED # sons = []
177 # DEPRECATED # start_step = 1
179 # DEPRECATED # # STEP 1
180 # DEPRECATED # # If the user already exists (is logged), let's display a summary of his account details
181 # DEPRECATED # # Otherwise propose a form to fill in
182 # DEPRECATED # if the_user(request):
183 # DEPRECATED # # Fill a disabled form with user info
184 # DEPRECATED # # Please logout to register another user
185 # DEPRECATED # sons.append(Raw(page=p, title=STEP1_TITLE, togglable=False, html=STEP0))
186 # DEPRECATED # start_step += 1
188 # DEPRECATED # # We could pass a list of fields also, instead of retrieving them from metadata
189 # DEPRECATED # # Otherwise we need some heuristics to display nice forms
190 # DEPRECATED # # XXX Could we log the user in after the form is validated ?
191 # DEPRECATED # # XXX Explain the password is for XXX
192 # DEPRECATED # field_list = [{
193 # DEPRECATED # 'name' : 'First name',
194 # DEPRECATED # 'field' : 'firstname',
195 # DEPRECATED # 'type' : 'text',
196 # DEPRECATED # 'validate_rx' : '^[a-zA-Z -]+$',
197 # DEPRECATED # 'validate_err': 'Your first name must be comprised of letters only',
198 # DEPRECATED # 'description' : 'Enter your first name',
200 # DEPRECATED # 'name' : 'Last name',
201 # DEPRECATED # 'field' : 'lastname',
202 # DEPRECATED # 'type' : 'text',
203 # DEPRECATED # 'validate_rx' : '^[a-zA-Z -]+$',
204 # DEPRECATED # 'validate_err': 'Your last name must be comprised of letters only',
205 # DEPRECATED # 'description' : 'Enter your last name',
207 # DEPRECATED # 'name' : 'Email',
208 # DEPRECATED # 'field' : 'email',
209 # DEPRECATED # 'type' : 'text',
210 # DEPRECATED # 'description' : 'Enter your email address',
212 # DEPRECATED # 'name' : 'Password',
213 # DEPRECATED # 'field' : 'password',
214 # DEPRECATED # 'type' : 'password',
215 # DEPRECATED # 'description' : 'Enter your password',
217 # DEPRECATED # 'name' : 'Confirm password',
218 # DEPRECATED # 'field' : 'password2',
219 # DEPRECATED # 'type' : 'password',
220 # DEPRECATED # 'description' : 'Enter your password again',
222 # DEPRECATED # sons.append(CreateForm(page = p, title = STEP1_TITLE, togglable = False, object = 'local:user', fields = field_list))
224 # DEPRECATED # # STEP 2
225 # DEPRECATED # # If the user already exists (is logged), let's display a summary of its institution
226 # DEPRECATED # # Otherwise propose a form to fill in (we should base our selection on the email)
227 # DEPRECATED # if the_user(request):
228 # DEPRECATED # # Fill a disabled form with institution
229 # DEPRECATED # # Please logout to register another user
230 # DEPRECATED # sons.append(Raw(page=p, title=STEP2_TITLE, togglable=False, html="User created"))
231 # DEPRECATED # start_step += 1
233 # DEPRECATED # sons.append(CreateForm(page = p, title = STEP2_TITLE, togglable = False, object = 'slice')) #institution'))
235 # DEPRECATED # # STEP3
236 # DEPRECATED # # Please should your prefered authentication method
237 # DEPRECATED # # This step should allow the user to either choose the user or managed mode in MySlice
238 # DEPRECATED # sons.append(Raw(page = p, title = STEP3_TITLE, togglable = False, html = STEP2_HTML))
240 # DEPRECATED # # Step 4: Request a slice (optional)
241 # DEPRECATED # sons.append(CreateForm(page = p, title = STEP4_TITLE, togglable = False, object = 'slice'))
243 # DEPRECATED # # Step 5: Your request is waiting for validation
244 # DEPRECATED # # Periodic refresh
245 # DEPRECATED # sons.append(Raw(page = p, title = STEP5_TITLE, togglable = False, html = STEP4))
247 # DEPRECATED # # Step 6: Account validation = welcome for newly validated users
248 # DEPRECATED # # . delegation
249 # DEPRECATED # # . platforms
250 # DEPRECATED # # . slice
251 # DEPRECATED # # . pointers
252 # DEPRECATED # sons.append(Raw(page = p, title = STEP6_TITLE, togglable = False, html = STEP5))
254 # DEPRECATED # wizard = Wizard(
255 # DEPRECATED # page = p,
256 # DEPRECATED # title = WIZARD_TITLE,
257 # DEPRECATED # togglable = False,
258 # DEPRECATED # sons = sons,
259 # DEPRECATED # start_step = start_step,
262 # DEPRECATED # p << wizard.render(request) # in portal page if possible
264 # DEPRECATED # return p.render()