Merge branch 'jordan' of ssh://git.onelab.eu/git/myslice into jordan
[myslice.git] / portal / views.py
1 # -*- coding: utf-8 -*-
2 #
3 # portal/urls.py: URL mappings for the portal application
4 # This file is part of the Manifold project.
5 #
6 # Authors:
7 #   Jordan Augé <jordan.auge@lip6.fr>
8 # Copyright 2013, UPMC Sorbonne Universités / LIP6
9 #
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.
13
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
17 # details.
18
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.
22
23 from django.shortcuts import render
24 from portal.forms     import RegisterUserForm
25
26 def user_register(request):
27     if request.method == 'POST':
28         form = RegisterUserForm(request.POST) # Nous reprenons les données
29         if form.is_valid():
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
42             #envoi = True
43     else:
44         form = RegisterUserForm()
45     return render(request, 'register_user.html', locals())
46     pass
47
48 def user_validate(request):
49     pass
50
51 def slice_request(request):
52     pass
53
54 def slice_validate(request):
55     pass
56
57 # DEPRECATED #from portal.portalpage  import PortalPage
58 # DEPRECATED #from plugins.wizard     import Wizard
59 # DEPRECATED #from plugins.form       import CreateForm
60 # DEPRECATED #from plugins.raw.raw    import Raw          # XXX
61 # DEPRECATED #
62 # DEPRECATED #from myslice.viewutils  import the_user
63 # DEPRECATED #
64 # DEPRECATED #from django.template.loader import render_to_string
65 # DEPRECATED #from django.template import RequestContext
66 # DEPRECATED #from django.views import generic
67 # DEPRECATED #
68 # DEPRECATED #from django.contrib.formtools.wizard.views import NamedUrlSessionWizardView
69 # DEPRECATED ##from django.core.files.storage import FileSystemStorage
70 # DEPRECATED #from django.core.files.storage import default_storage
71 # DEPRECATED #
72 # DEPRECATED ##class MerlinWizard(NamedUrlSessionWizardView):
73 # DEPRECATED ##
74 # DEPRECATED ##    ...
75 # DEPRECATED ##    ...
76 # DEPRECATED ##
77 # DEPRECATED ##    @classonlymethod
78 # DEPRECATED ##    def as_view(cls, *args, **kwargs):
79 # DEPRECATED ##        kwargs.update({
80 # DEPRECATED ##            'form_list': [
81 # DEPRECATED ##                NameForm,
82 # DEPRECATED ##                QuestForm,
83 # DEPRECATED ##                ColorForm,
84 # DEPRECATED ##            ],
85 # DEPRECATED ##            'url_name': 'merlin_wizard'
86 # DEPRECATED ##        })
87 # DEPRECATED ##        return super(MerlinWizard, cls).as_view(*args, **kwargs)
88 # DEPRECATED #
89 # DEPRECATED #class RegisterUserWizardView(NamedUrlSessionWizardView):
90 # DEPRECATED ##class RegisterUserWizardView(LoginRequiredMixin, NamedUrlSessionWizardView):
91 # DEPRECATED #    # Notice that I specify a file storage instance. If you don't specify this,
92 # DEPRECATED #    # and you need to support FileField or ImageField in your forms, you'll get
93 # DEPRECATED #    # errors from Django. This is something else I think could be handled by
94 # DEPRECATED #    # the views better. Seems to me that it should just use whatever the
95 # DEPRECATED #    # default/specified storage is for the rest of your project/application.
96 # DEPRECATED #    file_storage = default_storage # FileSystemStorage()
97 # DEPRECATED #    template_name = "register_user_wizard.html"
98 # DEPRECATED #
99 # DEPRECATED #    def done(self, form_list, **kwargs):
100 # DEPRECATED #        step1_form = form_list[0]
101 # DEPRECATED #        step2_form = form_list[1]
102 # DEPRECATED #
103 # DEPRECATED #        productext = self.create_product(product_form)
104 # DEPRECATED #        shippings = self.create_shippings(productext, shipping_forms)
105 # DEPRECATED #        images = self.create_images(productext, image_forms)
106 # DEPRECATED #
107 # DEPRECATED #        if all([productext, shippings, images]):
108 # DEPRECATED #            del self.request.session["wizard_product_wizard_view"]
109 # DEPRECATED #
110 # DEPRECATED #            messages.success(self.request,
111 # DEPRECATED #                _("Your product has been created."))
112 # DEPRECATED #            return HttpResponseRedirect(self.get_success_url(productext))
113 # DEPRECATED #
114 # DEPRECATED #        messages.error(self.request, _("Something went wrong creating your "
115 # DEPRECATED #            "product. Please try again or contact support."))
116 # DEPRECATED #        return HttpResponseRedirect(reverse("register_wizard"))
117 # DEPRECATED #
118 # DEPRECATED #    #def get_form_kwargs(self, step):
119 # DEPRECATED #    #    if step == "product":
120 # DEPRECATED #    #        return {"user": self.request.user}
121 # DEPRECATED #    #    return {}
122 # DEPRECATED #
123 # DEPRECATED ## The portal should hook the slice and user creation pages
124 # DEPRECATED #
125 # DEPRECATED #def register_user(request):
126 # DEPRECATED #    
127 # DEPRECATED #    if request.method == 'POST':
128 # DEPRECATED #        form = RegisterUserForm(request.POST) # Nous reprenons les données
129 # DEPRECATED #        if form.is_valid():
130 # DEPRECATED #            first_name = form.cleaned_data['first_name']
131 # DEPRECATED #            last_name  = form.cleaned_data['last_name']
132 # DEPRECATED #            email      = form.cleaned_data['email']
133 # DEPRECATED #            password   = form.cleaned_data['password']
134 # DEPRECATED #            password2  = form.cleaned_data['password2']
135 # DEPRECATED #            keypair    = form.cleaned_data['keypair']
136 # DEPRECATED #            ## Ici nous pouvons traiter les données du formulaire
137 # DEPRECATED #            #sujet = form.cleaned_data['sujet']
138 # DEPRECATED #            #message = form.cleaned_data['message']
139 # DEPRECATED #            #envoyeur = form.cleaned_data['envoyeur']
140 # DEPRECATED #            #renvoi = form.cleaned_data['renvoi']
141 # DEPRECATED #            ## Nous pourrions ici envoyer l'e-mail grâce aux données que nous venons de récupérer
142 # DEPRECATED #            #envoi = True
143 # DEPRECATED #    else:
144 # DEPRECATED #        form = RegisterUserForm()
145 # DEPRECATED #    return render(request, 'register_user.html', locals())
146 # DEPRECATED #
147 # DEPRECATED #def index(request):
148 # DEPRECATED #
149 # DEPRECATED #    WIZARD_TITLE = 'User registration'
150 # DEPRECATED #    STEP1_TITLE  = 'Enter your details'
151 # DEPRECATED #    STEP2_TITLE  = 'Select your institution'
152 # DEPRECATED #    STEP3_TITLE  = 'Authentication'
153 # DEPRECATED #    STEP4_TITLE  = 'Request a slice (optional)'
154 # DEPRECATED #    STEP5_TITLE  = 'Waiting for validation'
155 # DEPRECATED #    STEP6_TITLE  = 'Account validated'
156 # DEPRECATED #
157 # DEPRECATED #    STEP0 = render_to_string('account_validated.html', context_instance=RequestContext(request))
158 # DEPRECATED #    STEP2_HTML   = """
159 # DEPRECATED #    coucou
160 # DEPRECATED #    """
161 # DEPRECATED #    STEP4 = """
162 # DEPRECATED #    mede
163 # DEPRECATED #    """
164 # DEPRECATED #    STEP5 = render_to_string('account_validated.html', context_instance=RequestContext(request))
165 # DEPRECATED #
166 # DEPRECATED #    p = PortalPage(request)
167 # DEPRECATED #
168 # DEPRECATED #    # This is redundant with the Wizard title
169 # DEPRECATED #    p << "<h3>User registration</h3>"
170 # DEPRECATED #
171 # DEPRECATED #    sons = []
172 # DEPRECATED #    start_step = 1
173 # DEPRECATED #
174 # DEPRECATED #    # STEP 1
175 # DEPRECATED #    # If the user already exists (is logged), let's display a summary of his account details
176 # DEPRECATED #    # Otherwise propose a form to fill in
177 # DEPRECATED #    if the_user(request):
178 # DEPRECATED #        # Fill a disabled form with user info
179 # DEPRECATED #        # Please logout to register another user
180 # DEPRECATED #        sons.append(Raw(page=p, title=STEP1_TITLE, togglable=False, html=STEP0))
181 # DEPRECATED #        start_step += 1
182 # DEPRECATED #    else:
183 # DEPRECATED #        # We could pass a list of fields also, instead of retrieving them from metadata
184 # DEPRECATED #        # Otherwise we need some heuristics to display nice forms
185 # DEPRECATED #        # XXX Could we log the user in after the form is validated ?
186 # DEPRECATED #        # XXX Explain the password is for XXX
187 # DEPRECATED #        field_list = [{
188 # DEPRECATED #            'name'        : 'First name',
189 # DEPRECATED #            'field'       : 'firstname',
190 # DEPRECATED #            'type'        : 'text',
191 # DEPRECATED #            'validate_rx' : '^[a-zA-Z -]+$',
192 # DEPRECATED #            'validate_err': 'Your first name must be comprised of letters only',
193 # DEPRECATED #            'description' : 'Enter your first name',
194 # DEPRECATED #        }, {
195 # DEPRECATED #            'name'        : 'Last name',
196 # DEPRECATED #            'field'       : 'lastname',
197 # DEPRECATED #            'type'        : 'text',
198 # DEPRECATED #            'validate_rx' : '^[a-zA-Z -]+$',
199 # DEPRECATED #            'validate_err': 'Your last name must be comprised of letters only',
200 # DEPRECATED #            'description' : 'Enter your last name',
201 # DEPRECATED #        }, { 
202 # DEPRECATED #            'name'        : 'Email',
203 # DEPRECATED #            'field'       : 'email',
204 # DEPRECATED #            'type'        : 'text',
205 # DEPRECATED #            'description' : 'Enter your email address',
206 # DEPRECATED #        }, {
207 # DEPRECATED #            'name'        : 'Password',
208 # DEPRECATED #            'field'       : 'password',
209 # DEPRECATED #            'type'        : 'password',
210 # DEPRECATED #            'description' : 'Enter your password',
211 # DEPRECATED #        }, {
212 # DEPRECATED #            'name'        : 'Confirm password',
213 # DEPRECATED #            'field'       : 'password2',
214 # DEPRECATED #            'type'        : 'password',
215 # DEPRECATED #            'description' : 'Enter your password again',
216 # DEPRECATED #        }]
217 # DEPRECATED #        sons.append(CreateForm(page = p, title = STEP1_TITLE, togglable = False, object = 'local:user', fields = field_list))
218 # DEPRECATED #
219 # DEPRECATED #    # STEP 2
220 # DEPRECATED #    # If the user already exists (is logged), let's display a summary of its institution
221 # DEPRECATED #    # Otherwise propose a form to fill in (we should base our selection on the email)
222 # DEPRECATED #    if the_user(request):
223 # DEPRECATED #        # Fill a disabled form with institution
224 # DEPRECATED #        # Please logout to register another user
225 # DEPRECATED #        sons.append(Raw(page=p, title=STEP2_TITLE, togglable=False, html="User created"))
226 # DEPRECATED #        start_step += 1
227 # DEPRECATED #    else:
228 # DEPRECATED #        sons.append(CreateForm(page = p, title = STEP2_TITLE, togglable = False, object = 'slice')) #institution'))
229 # DEPRECATED #
230 # DEPRECATED #    # STEP3
231 # DEPRECATED #    # Please should your prefered authentication method
232 # DEPRECATED #    # This step should allow the user to either choose the user or managed mode in MySlice
233 # DEPRECATED #    sons.append(Raw(page = p, title = STEP3_TITLE, togglable = False, html = STEP2_HTML))
234 # DEPRECATED #
235 # DEPRECATED #    # Step 4: Request a slice (optional)
236 # DEPRECATED #    sons.append(CreateForm(page = p, title = STEP4_TITLE, togglable = False, object = 'slice'))
237 # DEPRECATED #
238 # DEPRECATED #    # Step 5: Your request is waiting for validation
239 # DEPRECATED #    # Periodic refresh
240 # DEPRECATED #    sons.append(Raw(page = p, title = STEP5_TITLE, togglable = False, html = STEP4))
241 # DEPRECATED #
242 # DEPRECATED #    # Step 6: Account validation  = welcome for newly validated users
243 # DEPRECATED #    # . delegation
244 # DEPRECATED #    # . platforms
245 # DEPRECATED #    # . slice
246 # DEPRECATED #    # . pointers
247 # DEPRECATED #    sons.append(Raw(page = p, title = STEP6_TITLE, togglable = False, html = STEP5))
248 # DEPRECATED #
249 # DEPRECATED #    wizard = Wizard(
250 # DEPRECATED #        page       = p,
251 # DEPRECATED #        title      = WIZARD_TITLE,
252 # DEPRECATED #        togglable  = False,
253 # DEPRECATED #        sons       = sons,
254 # DEPRECATED #        start_step = start_step,
255 # DEPRECATED #    )
256 # DEPRECATED #
257 # DEPRECATED #    p << wizard.render(request) # in portal page if possible
258 # DEPRECATED #
259 # DEPRECATED #    return p.render()