~moovida-developers/moovida/account

« back to all changes in this revision

Viewing changes to elisa-plugins/elisa/plugins/account/new_account.py

  • Committer: Philippe Normand
  • Date: 2009-09-15 16:41:29 UTC
  • mfrom: (1498.5.57 account_creation)
  • Revision ID: philippe@fluendo.com-20090915164129-9fwrd3vg84hvdjk8
new_account controllers refactored

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from elisa.core import common, media_uri
20
20
from elisa.core.utils import defer
21
 
from elisa.core.utils.i18n import install_translation, get_current_locale
 
21
from elisa.core.utils.i18n import install_translation
22
22
 
23
23
from elisa.plugins.pigment.pigment_controller import PigmentController
24
24
 
36
36
_ = install_translation('account')
37
37
_p = install_translation('poblesec')
38
38
 
39
 
class IntroAccountController(PigmentController):
 
39
 
 
40
class GenericInformationController(PigmentController):
 
41
    """
 
42
    A generic controller displaying popup with some information.
 
43
    
 
44
    It defines also default reactions for the most popular options 
 
45
    presented to user. 
 
46
    """
 
47
    
 
48
    def initialize(self, **kwargs):
 
49
        self.information = None
 
50
        for key, value in kwargs.iteritems():
 
51
            setattr(self, '_%s' % key, value)
 
52
        dfr = super(GenericInformationController, self).initialize()
 
53
        dfr.addCallback(self._create_widget)
 
54
        return dfr
 
55
 
 
56
    def clean(self):
 
57
        self.information.clean()
 
58
        self.information = None
 
59
        return super(GenericInformationController, self).clean()
 
60
 
 
61
    def _create_widget(self, controller):
 
62
        self.information = self.set_information()
 
63
        self.widget.add(self.information)
 
64
        self.information.visible = True
 
65
        self.widget.set_focus_proxy(self.information)
 
66
        return controller
 
67
 
 
68
    def set_information(self):
 
69
        """
 
70
        Create the popup with desired information (tile, subtitle, text) and 
 
71
        options (buttons) to chose from.
 
72
        
 
73
        Should be overridden by subclasses.
 
74
        
 
75
        @return:     widget with information
 
76
        @type:       L{elisa.plugins.pigment.widgets.widget.Widget}
 
77
        """
 
78
        return None
 
79
 
 
80
    def _go_back(self):
 
81
        return self.browser.load_previous_controller()
 
82
 
 
83
    def _use_moovida(self):
 
84
        self.browser.done()
 
85
    
 
86
    def _go_login(self, can_go_back=False):
 
87
        controller_path = '/poblesec/account/login_with_email'
 
88
        return self.browser.load_new_controller(controller_path,
 
89
                                                can_go_back=can_go_back)
 
90
 
 
91
    def _resend_validation(self):
 
92
        def sent(result):
 
93
            controller_path = '/poblesec/new_account/revalidate'
 
94
            dfr = self.browser.load_new_controller(controller_path,
 
95
                                                   email=self._email)
 
96
            return dfr
 
97
 
 
98
        uri = '%s://%s/account/%s/validation/%s/resend_validation_email' \
 
99
              % (HTTP_PROTO, API_SERVER, API_VERSION, self._email)
 
100
        resource_manager = common.application.resource_manager
 
101
        model, dfr = resource_manager.get(media_uri.MediaUri(uri))
 
102
        dfr.addCallback(sent)
 
103
        return dfr
 
104
 
 
105
    def _resend_password(self):
 
106
        def sent(result):
 
107
            controller_path = '/poblesec/account/password_requested'
 
108
            dfr = self.browser.load_new_controller(controller_path,
 
109
                                                   email=self._email)
 
110
            return dfr
 
111
 
 
112
        uri = '%s://%s/account/%s/validation/%s/change_password' \
 
113
              % (HTTP_PROTO, API_SERVER, API_VERSION, self._email)
 
114
        resource_manager = common.application.resource_manager
 
115
        model, dfr = resource_manager.get(media_uri.MediaUri(uri))
 
116
        dfr.addCallback(sent)
 
117
        return dfr
 
118
 
 
119
 
 
120
class IntroAccountController(GenericInformationController):
40
121
    """ Screen displayed after the intro video to allow the user to
41
122
    create an account.
42
123
    """
43
124
 
44
 
    def initialize(self):
45
 
        self.information = None
46
 
        dfr = super(IntroAccountController, self).initialize()
47
 
        dfr.addCallback(self._create_widget)
48
 
        return dfr
49
 
 
50
 
    def clean(self):
51
 
        self.information.clean()
52
 
        self.information = None
53
 
        return super(IntroAccountController, self).clean()
54
 
 
55
 
    def _create_widget(self, controller):
 
125
    def set_information(self):
56
126
        title = _("CREATE A MOOVIDA ACCOUNT")
57
127
        text = _("Create an account now, password protect and personalise "\
58
128
                 "your copy of Moovida.\nSet a profile for future social "\
60
130
                 "selected plugins.")
61
131
        buttons = [(_("Create New Account"), self._create_account),
62
132
                   (_("No Thanks"), self._no_thanks),
63
 
                   (_("Log In"), self._go_login),
 
133
                   (_("Log In"), lambda: self._go_login(can_go_back=True)),
64
134
                   (_("Help"), self._go_help),]
65
 
        self.information = WelcomePopup(title, text, buttons)
66
 
        self.widget.add(self.information)
67
 
        self.information.visible = True
68
 
        self.widget.set_focus_proxy(self.information)
69
 
        return controller
 
135
        return WelcomePopup(title, text, buttons)
70
136
 
71
137
    def _no_thanks(self):
72
138
        dfr = utils.create_instance()
76
142
        controller_path = '/poblesec/new_account/create'
77
143
        return self.browser.load_new_controller(controller_path)
78
144
 
79
 
    def _go_login(self):
80
 
        controller_path = '/poblesec/account/login_with_email'
81
 
        return self.browser.load_new_controller(controller_path,
82
 
                                                can_go_back=True)
83
 
 
84
145
    def _go_help(self):
85
146
        controller_path = '/poblesec/new_account/help'
86
147
        return self.browser.load_new_controller(controller_path,
113
174
 
114
175
    def login(self, email, password):
115
176
        # Overridden from mother class.
116
 
        self.email = email
117
177
 
118
178
        def user_created(user_model):
119
179
            controller_path = '/poblesec/new_account/validate'
120
 
            dfr = self.browser.load_new_controller(controller_path,
121
 
                                                   can_go_back=True,
122
 
                                                   email=self.email)
123
 
            return dfr
 
180
            return self.browser.load_new_controller(controller_path,
 
181
                                                    can_go_back=True,
 
182
                                                    email=email)
124
183
 
125
184
        def user_create_failed(failure):
126
185
            error_model = failure.value.error_model
127
186
            already_validated = hasattr(error_model, 'user') and \
128
187
                                error_model.user.validated
129
188
            controller_path = '/poblesec/new_account/conflict'
130
 
            kw = dict(can_go_back=True, email=self.email,
 
189
            kw = dict(can_go_back=True, email=email,
131
190
                      already_validated=already_validated)
132
 
            dfr = self.browser.load_new_controller(controller_path, **kw)
133
 
            return dfr
134
 
 
135
 
        def get_instance_and_create_user(failure):
136
 
            dfr = utils.get_instance()
137
 
            dfr.addCallback(create_moovida_user)
138
 
            dfr.addErrback(user_create_failed)
139
 
            return dfr
140
 
 
141
 
        def create_moovida_user(instance_model):
142
 
            provider = resource_provider.get_account_provider()
143
 
            user_model = models.UserModel()
144
 
            user_model.instances.append(instance_model)
145
 
            user_model.email = email
146
 
            user_model.password = password
147
 
 
148
 
            # username & name would be configurable in profile UI
149
 
            user_model.username = email
150
 
            user_model.name = email
151
 
            user_model.language = get_current_locale()
152
 
            user_model.step = 0
153
 
            user_model.validated = False
154
 
 
155
 
            uri = '%s://%s/account/%s/user' % (HTTP_PROTO, API_SERVER,
156
 
                                               API_VERSION)
157
 
            resource_manager = common.application.resource_manager
158
 
            dfr = resource_manager.post(media_uri.MediaUri(uri),
159
 
                                        model=user_model)
160
 
            dfr.addCallback(user_created)
161
 
            dfr.addErrback(user_create_failed)
162
 
            return dfr
163
 
 
164
 
        def create_account():
165
 
            dfr = utils.create_instance()
166
 
            dfr.addCallback(create_moovida_user)
167
 
            dfr.addErrback(get_instance_and_create_user)
168
 
            return dfr
 
191
            return self.browser.load_new_controller(controller_path, **kw)
169
192
 
170
193
        if not email:
171
194
            controller_path = '/poblesec/new_account/no_email_given'
176
199
            dfr = self.browser.load_new_controller(controller_path,
177
200
                                                   can_go_back=True)
178
201
        else:
179
 
            dfr = create_account()
 
202
            dfr = utils.create_account(email, password)
 
203
            dfr.addCallback(user_created)
 
204
            dfr.addErrback(user_create_failed)
180
205
        return dfr
181
206
 
182
 
class NoEmailGivenController(PigmentController):
 
207
class NoEmailGivenController(GenericInformationController):
183
208
    """ Screen displayed if user gave no email during account creation
184
209
    """
185
210
 
186
 
    def initialize(self):
187
 
        self.information = None
188
 
        dfr = super(NoEmailGivenController, self).initialize()
189
 
        dfr.addCallback(self._create_widget)
190
 
        return dfr
191
 
 
192
 
    def clean(self):
193
 
        self.information.clean()
194
 
        self.information = None
195
 
        return super(NoEmailGivenController, self).clean()
196
 
 
197
 
    def _create_widget(self, controller):
 
211
    def set_information(self):
198
212
        # FIXME: to validate with Designer Boys
199
213
        title = _("ACCOUNT CREATION")
200
214
        subtitle = _("We Want Your Email")
201
215
        text = _("Please give us a valid email address, if possible.")
202
216
        buttons = [(_("Close"), self._go_back),]
203
 
        self.information = modal_popup.ErrorPopup(title, subtitle,
 
217
        information = modal_popup.ErrorPopup(title, subtitle,
204
218
                                                  text, buttons)
205
 
        self.information.set_name("new_account")
206
 
        self.widget.add(self.information)
207
 
        self.information.visible = True
208
 
        self.widget.set_focus_proxy(self.information)
209
 
        return controller
210
 
 
211
 
    def _go_back(self):
212
 
        self.browser.load_previous_controller()
213
 
 
214
 
 
215
 
class NoPasswordGivenController(PigmentController):
 
219
        information.set_name("new_account")
 
220
        return information
 
221
 
 
222
 
 
223
class NoPasswordGivenController(GenericInformationController):
216
224
    """ Screen displayed if user gave no password during account creation
217
225
    """
218
226
 
219
 
    def initialize(self):
220
 
        self.information = None
221
 
        dfr = super(NoPasswordGivenController, self).initialize()
222
 
        dfr.addCallback(self._create_widget)
223
 
        return dfr
224
 
 
225
 
    def clean(self):
226
 
        self.information.clean()
227
 
        self.information = None
228
 
        return super(NoPasswordGivenController, self).clean()
229
 
 
230
 
    def _create_widget(self, controller):
 
227
    def set_information(self):
231
228
        # FIXME: to validate with Designer Boys
232
229
        title = _("ACCOUNT CREATION")
233
230
        subtitle = _("We Want Your Passwordz")
234
231
        text = _("Please give us a password.")
235
232
        buttons = [(_("Close"), self._go_back),]
236
 
        self.information = modal_popup.ErrorPopup(title, subtitle,
 
233
        information = modal_popup.ErrorPopup(title, subtitle,
237
234
                                                  text, buttons)
238
 
        self.information.set_name("new_account")
239
 
        self.widget.add(self.information)
240
 
        self.information.visible = True
241
 
        self.widget.set_focus_proxy(self.information)
242
 
        return controller
243
 
 
244
 
    def _go_back(self):
245
 
        self.browser.load_previous_controller()
246
 
 
247
 
 
248
 
class EmailValidationController(PigmentController):
 
235
        information.set_name("new_account")
 
236
        return information
 
237
 
 
238
 
 
239
class EmailValidationController(GenericInformationController):
249
240
    """ Screen displayed after successful account creation
250
241
    """
251
242
 
252
 
    def initialize(self, email=None):
253
 
        self.email = email
254
 
        self.information = None
255
 
        dfr = super(EmailValidationController, self).initialize()
256
 
        dfr.addCallback(self._create_widget)
257
 
        return dfr
258
 
 
259
 
    def clean(self):
260
 
        self.information.clean()
261
 
        self.information = None
262
 
        return super(EmailValidationController, self).clean()
263
 
 
264
 
    def _create_widget(self, controller):
265
 
        email = self.email
 
243
    def set_information(self):
 
244
        email = self._email
266
245
        title = _("ACCOUNT VALIDATION")
267
246
        subtitle = _("Your Moovida Account Has Been Registered")
268
247
        text = _("Please review the Moovida account confirmation email "\
271
250
                 "as well as other useful information.\n\nThank You "\
272
251
                 "for joining Moovida!")
273
252
        buttons = [(_("Use Moovida"), self._use_moovida),]
274
 
        self.information = modal_popup.ErrorPopup(title, subtitle,
 
253
        information = modal_popup.ErrorPopup(title, subtitle,
275
254
                                                  text % locals(),
276
255
                                                  buttons)
277
 
        self.information.set_name("new_account")
278
 
        self.widget.add(self.information)
279
 
        self.information.visible = True
280
 
        self.widget.set_focus_proxy(self.information)
281
 
        return controller
282
 
 
283
 
    def _use_moovida(self):
284
 
        self.browser.done()
285
 
 
286
 
 
287
 
class EmailReValidationController(PigmentController):
 
256
        information.set_name("new_account")
 
257
        return information
 
258
 
 
259
 
 
260
class EmailReValidationController(GenericInformationController):
288
261
    """ Screen displayed when user has explicitely requested a new
289
262
    email validation link.
290
263
    """
291
264
 
292
 
    def initialize(self, email=None):
293
 
        self.email = email
294
 
        self.information = None
295
 
        dfr = super(EmailReValidationController, self).initialize()
296
 
        dfr.addCallback(self._create_widget)
297
 
        return dfr
298
 
 
299
 
    def clean(self):
300
 
        self.information.clean()
301
 
        self.information = None
302
 
        return super(EmailReValidationController, self).clean()
303
 
 
304
 
    def _create_widget(self, controller):
305
 
        email = self.email
 
265
    def set_information(self):
 
266
        email = self._email
306
267
        use_moovida_button = _("Use Moovida")
307
268
        login_button = _("Log In")
308
269
        title = _("ACCOUNT VALIDATION")
314
275
                 "can use Moovida without registration by clicking on "\
315
276
                 "'%(use_moovida_button)s'.")
316
277
        buttons = [(use_moovida_button, self._use_moovida),
317
 
                   (login_button, self._go_login),
 
278
                   (login_button, lambda: self._go_login(can_go_back=True)),
318
279
                   ]
319
 
        self.information = modal_popup.ErrorPopup(title, subtitle,
 
280
        information = modal_popup.ErrorPopup(title, subtitle,
320
281
                                                  text % locals(),
321
282
                                                  buttons)
322
 
        self.information.set_name("new_account")
323
 
        self.widget.add(self.information)
324
 
        self.information.visible = True
325
 
        self.widget.set_focus_proxy(self.information)
326
 
        return controller
327
 
 
328
 
    def _use_moovida(self):
329
 
        self.browser.done()
330
 
 
331
 
    def _go_login(self):
332
 
        controller_path = '/poblesec/account/login'
333
 
        dfr = self.browser.load_new_controller(controller_path,
334
 
                                               can_go_back=True,
335
 
                                               email=self.email)
336
 
        return dfr
337
 
 
338
 
 
339
 
class AccountConflictController(PigmentController):
 
283
        information.set_name("new_account")
 
284
        return information
 
285
 
 
286
 
 
287
class AccountConflictController(GenericInformationController):
340
288
    """ Screen displayed after failed account creation
341
289
    """
342
290
 
343
 
    def initialize(self, email=None, already_validated=None):
344
 
        self.email = email
345
 
        self.already_validated = already_validated
346
 
        self.information = None
347
 
        dfr = super(AccountConflictController, self).initialize()
348
 
        dfr.addCallback(self._create_widget)
349
 
        return dfr
350
 
 
351
 
    def clean(self):
352
 
        self.information.clean()
353
 
        self.information = None
354
 
        return super(AccountConflictController, self).clean()
355
 
 
356
 
    def _create_widget(self, controller):
 
291
    def set_information(self):
357
292
        title = _("ACCOUNT ALREADY REGISTERED")
358
293
        close_button = _("Close")
359
294
        resend_password_button = _("Request New Password")
360
295
        resend_validation_button = _("Resend Validation Email")
361
296
        use_moovida_button = _("Use Moovida")
362
297
        login_button = _("Log In")
363
 
        email = self.email
364
 
        if self.already_validated:
 
298
        email = self._email
 
299
        if self._already_validated:
365
300
            subtitle = _("This Email Address Is Already In Use")
366
301
            text = _("The Email address <b>'%(email)s'</b> is already in "\
367
302
                     "use or has been registered by another user. If you "\
395
330
            buttons = [(close_button, self._go_back),
396
331
                       (resend_validation_button, self._resend_validation),
397
332
                       (use_moovida_button, self._use_moovida)]
398
 
        self.information = modal_popup.ErrorPopup(title, subtitle,
 
333
        information = modal_popup.ErrorPopup(title, subtitle,
399
334
                                                  text % locals(),
400
335
                                                  buttons)
401
 
        self.information.set_name("new_account")
402
 
        self.widget.add(self.information)
403
 
        self.information.visible = True
404
 
        self.widget.set_focus_proxy(self.information)
405
 
        return controller
406
 
 
407
 
    def _go_back(self):
408
 
        self.browser.load_previous_controller()
409
 
 
410
 
    def _go_login(self):
411
 
        controller_path = '/poblesec/account/login'
412
 
        dfr = self.browser.load_new_controller(controller_path,
413
 
                                               email=self.email)
414
 
        return dfr
415
 
 
416
 
    def _use_moovida(self):
417
 
        self.browser.done()
418
 
 
419
 
    def _resend_validation(self):
420
 
        def sent(result):
421
 
            controller_path = '/poblesec/new_account/revalidate'
422
 
            dfr = self.browser.load_new_controller(controller_path,
423
 
                                                   email=self.email)
424
 
            return dfr
425
 
 
426
 
        uri = '%s://%s/account/%s/validation/%s/resend_validation_email' \
427
 
              % (HTTP_PROTO, API_SERVER, API_VERSION, self.email)
428
 
        resource_manager = common.application.resource_manager
429
 
        model, dfr = resource_manager.get(media_uri.MediaUri(uri))
430
 
        dfr.addCallback(sent)
431
 
        return dfr
432
 
 
433
 
    def _resend_password(self):
434
 
        def sent(result):
435
 
            controller_path = '/poblesec/account/password_requested'
436
 
            dfr = self.browser.load_new_controller(controller_path,
437
 
                                                   email=self.email)
438
 
            return dfr
439
 
 
440
 
        uri = '%s://%s/account/%s/validation/%s/change_password' \
441
 
              % (HTTP_PROTO, API_SERVER, API_VERSION, self.email)
442
 
        resource_manager = common.application.resource_manager
443
 
        model, dfr = resource_manager.get(media_uri.MediaUri(uri))
444
 
        dfr.addCallback(sent)
445
 
        return dfr
 
336
        information.set_name("new_account")
 
337
        return information
 
338
 
446
339
 
447
340
class LoginMixin(object):
448
341
 
519
412
        self._password.visible = True
520
413
        self.keyboard.add_entry(self._password)
521
414
 
522
 
class LoginFailedController(PigmentController):
 
415
class LoginFailedController(GenericInformationController):
523
416
    """ Screen displayed if user gave a wrong password in the login
524
417
    form.
525
418
    """
526
419
 
527
 
    def initialize(self, email=None):
528
 
        self.email = email
529
 
        self.information = None
530
 
        dfr = super(LoginFailedController, self).initialize()
531
 
        dfr.addCallback(self._create_widget)
532
 
        return dfr
533
 
 
534
 
    def clean(self):
535
 
        self.information.clean()
536
 
        self.information = None
537
 
        return super(LoginFailedController, self).clean()
538
 
 
539
 
    def _create_widget(self, controller):
540
 
        email = self.email
 
420
    def set_information(self):
 
421
        email = self._email
541
422
        title = _("CURRENT PASSWORD INCORRECT")
542
423
        subtitle = _("Please Double Check Your Current Password")
543
424
        close_button = _("Close")
553
434
                 "return to your account screen by clicking on "\
554
435
                 "'%(retry_button)s'.")
555
436
        buttons = [(close_button, self._use_moovida),
556
 
                   (retry_button, self._retry),
 
437
                   (retry_button, self._go_back),
557
438
                   (resend_password_button, self._resend_password)]
558
 
        self.information = modal_popup.ErrorPopup(title, subtitle,
 
439
        information = modal_popup.ErrorPopup(title, subtitle,
559
440
                                                  text % locals(),
560
441
                                                  buttons)
561
 
        self.information.set_name("new_account")
562
 
        self.widget.add(self.information)
563
 
        self.information.visible = True
564
 
        self.widget.set_focus_proxy(self.information)
565
 
        return controller
566
 
 
567
 
    def _use_moovida(self):
568
 
        self.browser.done()
569
 
 
570
 
    def _retry(self):
571
 
        return self.browser.load_previous_controller()
572
 
 
573
 
    def _resend_password(self):
574
 
        def sent(result):
575
 
            controller_path = '/poblesec/account/password_requested'
576
 
            dfr = self.browser.load_new_controller(controller_path,
577
 
                                                   email=self.email)
578
 
            return dfr
579
 
 
580
 
        uri = '%s://%s/account/%s/validation/%s/change_password' \
581
 
              % (HTTP_PROTO, API_SERVER, API_VERSION, self.email)
582
 
        resource_manager = common.application.resource_manager
583
 
        model, dfr = resource_manager.get(media_uri.MediaUri(uri))
584
 
        dfr.addCallback(sent)
585
 
        return dfr
586
 
 
587
 
 
588
 
class SecondRunValidatedController(PigmentController):
 
442
        information.set_name("new_account")
 
443
        return information
 
444
 
 
445
 
 
446
class SecondRunValidatedController(GenericInformationController):
589
447
    """ Screen displayed at run > 1, only one time, if the user has
590
448
    validated his email address.
591
449
    """
592
450
 
593
 
    def initialize(self, email=None):
594
 
        self.email = email
595
 
        self.information = None
596
 
        dfr = super(SecondRunValidatedController, self).initialize()
597
 
        dfr.addCallback(self._create_widget)
598
 
        return dfr
599
 
 
600
 
    def clean(self):
601
 
        self.information.clean()
602
 
        self.information = None
603
 
        return super(SecondRunValidatedController, self).clean()
604
 
 
605
 
    def _create_widget(self, controller):
606
 
        email = self.email
 
451
    def set_information(self):
 
452
        email = self._email
607
453
        title = _("ACCOUNT VALIDATION")
608
454
        subtitle = _("Thank You For Joining Moovida!")
609
455
        login_button = _("Login Now")
619
465
                 "'%(resend_password_button)s' and your password will be "\
620
466
                 "sent to you via email.\nCan't login? You can still use "\
621
467
                 "Moovida by clicking on '%(use_moovida_button)s'.")
622
 
        buttons = [(login_button, self._go_login),
 
468
        buttons = [(login_button, lambda: self._go_login(can_go_back=True)),
623
469
                   (resend_password_button, self._resend_password),
624
470
                   (use_moovida_button, self._use_moovida)]
625
 
        self.information = modal_popup.InformationPopup(title, subtitle,
 
471
        information = modal_popup.InformationPopup(title, subtitle,
626
472
                                                        text % locals(),
627
473
                                                        buttons)
628
 
        self.information.set_name("new_account")
629
 
        self.widget.add(self.information)
630
 
        self.information.visible = True
631
 
        self.widget.set_focus_proxy(self.information)
632
 
        return controller
633
 
 
634
 
    def _use_moovida(self):
635
 
        self.browser.done()
636
 
 
637
 
    def _go_login(self):
638
 
        controller_path = '/poblesec/account/login'
639
 
        dfr = self.browser.load_new_controller(controller_path,
640
 
                                               can_go_back=True,
641
 
                                               email=self.email)
642
 
        return dfr
643
 
 
644
 
    def _resend_password(self):
645
 
        def sent(result):
646
 
            controller_path = '/poblesec/account/password_requested'
647
 
            dfr = self.browser.load_new_controller(controller_path,
648
 
                                                   email=self.email)
649
 
            return dfr
650
 
 
651
 
        uri = '%s://%s/account/%s/validation/%s/change_password' \
652
 
              % (HTTP_PROTO, API_SERVER, API_VERSION, self.email)
653
 
        resource_manager = common.application.resource_manager
654
 
        model, dfr = resource_manager.get(media_uri.MediaUri(uri))
655
 
        dfr.addCallback(sent)
656
 
        return dfr
657
 
 
658
 
class SecondRunNotValidatedController(PigmentController):
 
474
        information.set_name("new_account")
 
475
        return information
 
476
 
 
477
 
 
478
class SecondRunNotValidatedController(GenericInformationController):
659
479
    """ Screen displayed for each run > 1 until user validates his
660
480
    email address.
661
481
    """
662
482
 
663
 
    def initialize(self, email=None):
664
 
        self.email = email
665
 
        self.information = None
666
 
        dfr = super(SecondRunNotValidatedController, self).initialize()
667
 
        dfr.addCallback(self._create_widget)
668
 
        return dfr
669
 
 
670
 
    def clean(self):
671
 
        self.information.clean()
672
 
        self.information = None
673
 
        return super(SecondRunNotValidatedController, self).clean()
674
 
 
675
 
    def _create_widget(self, controller):
676
 
        email = self.email
 
483
    def set_information(self):
 
484
        email = self._email
677
485
        use_moovida_button = _("Use Without Login")
678
486
        resend_validation_email = _("Resend Validation Email")
679
487
        cancel_button = _("Cancel Account Process")
691
499
        buttons = [(use_moovida_button, self._use_moovida),
692
500
                   (resend_validation_email, self._resend_validation),
693
501
                   (cancel_button, self._remove_user)]
694
 
        self.information = modal_popup.ErrorPopup(title, subtitle,
 
502
        information = modal_popup.ErrorPopup(title, subtitle,
695
503
                                                  text % locals(), buttons)
696
 
        self.information.set_name("new_account")
697
 
        self.widget.add(self.information)
698
 
        self.information.visible = True
699
 
        self.widget.set_focus_proxy(self.information)
700
 
        return controller
701
 
 
702
 
    def _use_moovida(self):
703
 
        self.browser.done()
704
 
 
705
 
    def _resend_validation(self):
706
 
        def sent(result):
707
 
            controller_path = '/poblesec/new_account/revalidate'
708
 
            dfr = self.browser.load_new_controller(controller_path,
709
 
                                                   email=self.email)
710
 
            return dfr
711
 
 
712
 
        uri = '%s://%s/account/%s/validation/%s/resend_validation_email' \
713
 
              % (HTTP_PROTO, API_SERVER, API_VERSION, self.email)
714
 
        resource_manager = common.application.resource_manager
715
 
        model, dfr = resource_manager.get(media_uri.MediaUri(uri))
716
 
        dfr.addCallback(sent)
717
 
        return dfr
 
504
        information.set_name("new_account")
 
505
        return information
718
506
 
719
507
    def _remove_user(self):
720
508
        # TODO: DELETE /user/id
721
509
        pass
722
510
 
723
 
class NewPasswordRequestedController(PigmentController):
 
511
class NewPasswordRequestedController(GenericInformationController):
724
512
    """ Screen displayed when the user requested a new password for
725
513
    his account.
726
514
    """
727
515
 
728
 
    def initialize(self, email=None):
729
 
        self.email = email
730
 
        self.information = None
731
 
        dfr = super(NewPasswordRequestedController, self).initialize()
732
 
        dfr.addCallback(self._create_widget)
733
 
        return dfr
734
 
 
735
 
    def clean(self):
736
 
        self.information.clean()
737
 
        self.information = None
738
 
        return super(NewPasswordRequestedController, self).clean()
739
 
 
740
 
    def _create_widget(self, controller):
741
 
        email = self.email
 
516
    def set_information(self):
 
517
        email = self._email
742
518
        login_button = _("Log In")
743
519
        use_moovida_button = _("Use Moovida")
744
520
        title = _("REQUEST NEW PASSWORD")
755
531
                 "menu once you have setup your new password.")
756
532
        buttons = [(use_moovida_button, self._use_moovida),
757
533
                   (login_button, self._go_login)]
758
 
        self.information = modal_popup.ErrorPopup(title, subtitle,
 
534
        information = modal_popup.ErrorPopup(title, subtitle,
759
535
                                                  text % locals(), buttons)
760
 
        self.information.set_name("new_account")
761
 
        self.widget.add(self.information)
762
 
        self.information.visible = True
763
 
        self.widget.set_focus_proxy(self.information)
764
 
        return controller
765
 
 
766
 
    def _use_moovida(self):
767
 
        self.browser.done()
768
 
 
769
 
    def _go_login(self):
770
 
        controller_path = '/poblesec/account/login'
771
 
        dfr = self.browser.load_new_controller(controller_path,
772
 
                                               email=self.email)
773
 
        return dfr
774
 
 
775
 
class HelpController(PigmentController):
 
536
        information.set_name("new_account")
 
537
        return information
 
538
 
 
539
 
 
540
class HelpController(GenericInformationController):
776
541
    """ Screen displayed when the user requested some help before
777
542
    creating his account at first run.
778
543
    """
779
544
 
780
 
    def initialize(self):
781
 
        self.information = None
782
 
        dfr = super(HelpController, self).initialize()
783
 
        dfr.addCallback(self._create_widget)
784
 
        return dfr
785
 
 
786
 
    def clean(self):
787
 
        self.information.clean()
788
 
        self.information = None
789
 
        return super(HelpController, self).clean()
790
 
 
791
 
    def _create_widget(self, controller):
 
545
    def set_information(self):
792
546
        go_back_button = _("Close")
793
547
        title = _("BEATLES - HELP !")
794
548
        subtitle = _("I Need Somebody,")
819
573
Help me, get my feet back on the ground,
820
574
Won't you please, please help me, help me, help me, oh.""")
821
575
        buttons = [(go_back_button, self._go_back),]
822
 
        self.information = modal_popup.ErrorPopup(title, subtitle,
 
576
        information = modal_popup.ErrorPopup(title, subtitle,
823
577
                                                  text, buttons)
824
 
        self.information.set_name("new_account")
825
 
        self.widget.add(self.information)
826
 
        self.information.visible = True
827
 
        self.widget.set_focus_proxy(self.information)
828
 
        return controller
829
 
 
830
 
    def _go_back(self):
831
 
        return self.browser.load_previous_controller()
 
578
        information.set_name("new_account")
 
579
        return information