diff options
-rw-r--r-- | app/php/events/CalendarPreferenceEvents.php | 16 | ||||
-rw-r--r-- | app/php/facades/UserFacade.php | 20 |
2 files changed, 30 insertions, 6 deletions
diff --git a/app/php/events/CalendarPreferenceEvents.php b/app/php/events/CalendarPreferenceEvents.php new file mode 100644 index 0000000..76fa071 --- /dev/null +++ b/app/php/events/CalendarPreferenceEvents.php @@ -0,0 +1,16 @@ +<?php + +Prado::using('Application.events.EventModule'); +Prado::using('Application.model.User'); +Prado::using('Application.facades.CalendarFacade'); + +class CalendarPreferenceEvents extends EventModule { + + public function onUserRegistered(User $user) { + $facade = CalendarFacade::getInstance(); + $facade->setPreferredCalendars($user, $facade->getDefaultPreference()); + } + +} + +?> diff --git a/app/php/facades/UserFacade.php b/app/php/facades/UserFacade.php index 3e32a8d..69d634a 100644 --- a/app/php/facades/UserFacade.php +++ b/app/php/facades/UserFacade.php @@ -16,12 +16,20 @@ class UserFacade extends Facade { } public function registerUser($login, $password, $admin) { - $newUser = new User(); - $newUser->Login = $login; - $newUser->Password = $this->generatePassword($password); - $newUser->IsAdmin = $admin; - $newUser->save(); - return $newUser; + $transaction = $this->beginTransaction(); + try { + $newUser = new User(); + $newUser->Login = $login; + $newUser->Password = $this->generatePassword($password); + $newUser->IsAdmin = $admin; + $newUser->save(); + $this->raiseEvent('UserRegistered', $newUser); + $transaction->commit(); + return $newUser; + } catch (Exception $e) { + $transaction->rollback(); + throw $e; + } } public function changePassword(DbUser $user, $pass) { |