36
36
_ = install_translation('account')
37
37
_p = install_translation('poblesec')
39
class IntroAccountController(PigmentController):
40
class GenericInformationController(PigmentController):
42
A generic controller displaying popup with some information.
44
It defines also default reactions for the most popular options
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)
57
self.information.clean()
58
self.information = None
59
return super(GenericInformationController, self).clean()
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)
68
def set_information(self):
70
Create the popup with desired information (tile, subtitle, text) and
71
options (buttons) to chose from.
73
Should be overridden by subclasses.
75
@return: widget with information
76
@type: L{elisa.plugins.pigment.widgets.widget.Widget}
81
return self.browser.load_previous_controller()
83
def _use_moovida(self):
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)
91
def _resend_validation(self):
93
controller_path = '/poblesec/new_account/revalidate'
94
dfr = self.browser.load_new_controller(controller_path,
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)
105
def _resend_password(self):
107
controller_path = '/poblesec/account/password_requested'
108
dfr = self.browser.load_new_controller(controller_path,
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)
120
class IntroAccountController(GenericInformationController):
40
121
""" Screen displayed after the intro video to allow the user to
41
122
create an account.
45
self.information = None
46
dfr = super(IntroAccountController, self).initialize()
47
dfr.addCallback(self._create_widget)
51
self.information.clean()
52
self.information = None
53
return super(IntroAccountController, self).clean()
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)
135
return WelcomePopup(title, text, buttons)
71
137
def _no_thanks(self):
72
138
dfr = utils.create_instance()
114
175
def login(self, email, password):
115
176
# Overridden from mother class.
118
178
def user_created(user_model):
119
179
controller_path = '/poblesec/new_account/validate'
120
dfr = self.browser.load_new_controller(controller_path,
180
return self.browser.load_new_controller(controller_path,
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)
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)
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
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()
153
user_model.validated = False
155
uri = '%s://%s/account/%s/user' % (HTTP_PROTO, API_SERVER,
157
resource_manager = common.application.resource_manager
158
dfr = resource_manager.post(media_uri.MediaUri(uri),
160
dfr.addCallback(user_created)
161
dfr.addErrback(user_create_failed)
164
def create_account():
165
dfr = utils.create_instance()
166
dfr.addCallback(create_moovida_user)
167
dfr.addErrback(get_instance_and_create_user)
191
return self.browser.load_new_controller(controller_path, **kw)
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)
179
dfr = create_account()
202
dfr = utils.create_account(email, password)
203
dfr.addCallback(user_created)
204
dfr.addErrback(user_create_failed)
182
class NoEmailGivenController(PigmentController):
207
class NoEmailGivenController(GenericInformationController):
183
208
""" Screen displayed if user gave no email during account creation
186
def initialize(self):
187
self.information = None
188
dfr = super(NoEmailGivenController, self).initialize()
189
dfr.addCallback(self._create_widget)
193
self.information.clean()
194
self.information = None
195
return super(NoEmailGivenController, self).clean()
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,
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)
212
self.browser.load_previous_controller()
215
class NoPasswordGivenController(PigmentController):
219
information.set_name("new_account")
223
class NoPasswordGivenController(GenericInformationController):
216
224
""" Screen displayed if user gave no password during account creation
219
def initialize(self):
220
self.information = None
221
dfr = super(NoPasswordGivenController, self).initialize()
222
dfr.addCallback(self._create_widget)
226
self.information.clean()
227
self.information = None
228
return super(NoPasswordGivenController, self).clean()
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,
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)
245
self.browser.load_previous_controller()
248
class EmailValidationController(PigmentController):
235
information.set_name("new_account")
239
class EmailValidationController(GenericInformationController):
249
240
""" Screen displayed after successful account creation
252
def initialize(self, email=None):
254
self.information = None
255
dfr = super(EmailValidationController, self).initialize()
256
dfr.addCallback(self._create_widget)
260
self.information.clean()
261
self.information = None
262
return super(EmailValidationController, self).clean()
264
def _create_widget(self, controller):
243
def set_information(self):
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,
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)
283
def _use_moovida(self):
287
class EmailReValidationController(PigmentController):
256
information.set_name("new_account")
260
class EmailReValidationController(GenericInformationController):
288
261
""" Screen displayed when user has explicitely requested a new
289
262
email validation link.
292
def initialize(self, email=None):
294
self.information = None
295
dfr = super(EmailReValidationController, self).initialize()
296
dfr.addCallback(self._create_widget)
300
self.information.clean()
301
self.information = None
302
return super(EmailReValidationController, self).clean()
304
def _create_widget(self, controller):
265
def set_information(self):
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)),
319
self.information = modal_popup.ErrorPopup(title, subtitle,
280
information = modal_popup.ErrorPopup(title, subtitle,
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)
328
def _use_moovida(self):
332
controller_path = '/poblesec/account/login'
333
dfr = self.browser.load_new_controller(controller_path,
339
class AccountConflictController(PigmentController):
283
information.set_name("new_account")
287
class AccountConflictController(GenericInformationController):
340
288
""" Screen displayed after failed account creation
343
def initialize(self, email=None, already_validated=None):
345
self.already_validated = already_validated
346
self.information = None
347
dfr = super(AccountConflictController, self).initialize()
348
dfr.addCallback(self._create_widget)
352
self.information.clean()
353
self.information = None
354
return super(AccountConflictController, self).clean()
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")
364
if self.already_validated:
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,
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)
408
self.browser.load_previous_controller()
411
controller_path = '/poblesec/account/login'
412
dfr = self.browser.load_new_controller(controller_path,
416
def _use_moovida(self):
419
def _resend_validation(self):
421
controller_path = '/poblesec/new_account/revalidate'
422
dfr = self.browser.load_new_controller(controller_path,
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)
433
def _resend_password(self):
435
controller_path = '/poblesec/account/password_requested'
436
dfr = self.browser.load_new_controller(controller_path,
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)
336
information.set_name("new_account")
447
340
class LoginMixin(object):
519
412
self._password.visible = True
520
413
self.keyboard.add_entry(self._password)
522
class LoginFailedController(PigmentController):
415
class LoginFailedController(GenericInformationController):
523
416
""" Screen displayed if user gave a wrong password in the login
527
def initialize(self, email=None):
529
self.information = None
530
dfr = super(LoginFailedController, self).initialize()
531
dfr.addCallback(self._create_widget)
535
self.information.clean()
536
self.information = None
537
return super(LoginFailedController, self).clean()
539
def _create_widget(self, controller):
420
def set_information(self):
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,
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)
567
def _use_moovida(self):
571
return self.browser.load_previous_controller()
573
def _resend_password(self):
575
controller_path = '/poblesec/account/password_requested'
576
dfr = self.browser.load_new_controller(controller_path,
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)
588
class SecondRunValidatedController(PigmentController):
442
information.set_name("new_account")
446
class SecondRunValidatedController(GenericInformationController):
589
447
""" Screen displayed at run > 1, only one time, if the user has
590
448
validated his email address.
593
def initialize(self, email=None):
595
self.information = None
596
dfr = super(SecondRunValidatedController, self).initialize()
597
dfr.addCallback(self._create_widget)
601
self.information.clean()
602
self.information = None
603
return super(SecondRunValidatedController, self).clean()
605
def _create_widget(self, controller):
451
def set_information(self):
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,
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)
634
def _use_moovida(self):
638
controller_path = '/poblesec/account/login'
639
dfr = self.browser.load_new_controller(controller_path,
644
def _resend_password(self):
646
controller_path = '/poblesec/account/password_requested'
647
dfr = self.browser.load_new_controller(controller_path,
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)
658
class SecondRunNotValidatedController(PigmentController):
474
information.set_name("new_account")
478
class SecondRunNotValidatedController(GenericInformationController):
659
479
""" Screen displayed for each run > 1 until user validates his
663
def initialize(self, email=None):
665
self.information = None
666
dfr = super(SecondRunNotValidatedController, self).initialize()
667
dfr.addCallback(self._create_widget)
671
self.information.clean()
672
self.information = None
673
return super(SecondRunNotValidatedController, self).clean()
675
def _create_widget(self, controller):
483
def set_information(self):
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)
702
def _use_moovida(self):
705
def _resend_validation(self):
707
controller_path = '/poblesec/new_account/revalidate'
708
dfr = self.browser.load_new_controller(controller_path,
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)
504
information.set_name("new_account")
719
507
def _remove_user(self):
720
508
# TODO: DELETE /user/id
723
class NewPasswordRequestedController(PigmentController):
511
class NewPasswordRequestedController(GenericInformationController):
724
512
""" Screen displayed when the user requested a new password for
728
def initialize(self, email=None):
730
self.information = None
731
dfr = super(NewPasswordRequestedController, self).initialize()
732
dfr.addCallback(self._create_widget)
736
self.information.clean()
737
self.information = None
738
return super(NewPasswordRequestedController, self).clean()
740
def _create_widget(self, controller):
516
def set_information(self):
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)
766
def _use_moovida(self):
770
controller_path = '/poblesec/account/login'
771
dfr = self.browser.load_new_controller(controller_path,
775
class HelpController(PigmentController):
536
information.set_name("new_account")
540
class HelpController(GenericInformationController):
776
541
""" Screen displayed when the user requested some help before
777
542
creating his account at first run.
780
def initialize(self):
781
self.information = None
782
dfr = super(HelpController, self).initialize()
783
dfr.addCallback(self._create_widget)
787
self.information.clean()
788
self.information = None
789
return super(HelpController, self).clean()
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,
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)
831
return self.browser.load_previous_controller()
578
information.set_name("new_account")