1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Installer;
13
14 use ICanBoogie\Errors;
15 use ICanBoogie\HTTP\Request;
16 use ICanBoogie\I18n;
17 use ICanBoogie\I18n\FormattedString;
18
19 use Brickrouge\Element;
20
21 class UserOperation extends Operation
22 {
23 protected function get_controls()
24 {
25 return array
26 (
27 self::CONTROL_FORM => true
28 )
29
30 + parent::get_controls();
31 }
32
33 protected function get_form()
34 {
35 $form = new UserForm;
36
37 $form->children['password'][Element::REQUIRED] = true;
38 $form->children['password_confirm'][Element::REQUIRED] = true;
39
40 return $form;
41 }
42
43 public function __invoke(Request $request)
44 {
45 $random_password = $request['random_password'];
46
47 if ($random_password && !$request['password'] && !$request['password_confirm'])
48 {
49 $request['password'] = $random_password;
50 $request['password_confirm'] = $random_password;
51 }
52
53 return parent::__invoke($request);
54 }
55
56 protected function validate(Errors $errors)
57 {
58 $request = $this->request;
59
60 $password = $request['password'];
61 $password_confirm = $request['password_confirm'];
62
63 if ($password != $password_confirm)
64 {
65 $errors['password'] = I18n\t('panel.user.error.password_match');
66 $errors['password_confirm'] = true;
67 }
68
69 return $errors;
70 }
71
72 protected function process()
73 {
74 global $core;
75
76 $request = $this->request;
77
78 $core->session->install['user'] = array
79 (
80 'username' => $request['username'],
81 'email' => $request['email'],
82 'password' => $request['password'],
83 'language' => $request['language']
84 );
85
86 $this->response->message = I18n\t('panel.user.success');
87
88 return parent::process();
89 }
90 }