Code Duplication    Length = 37-39 lines in 2 locations

src/User/HTMLForm/CreateUserForm.php 1 location

@@ 77-113 (lines=37) @@
74
    *
75
    * @return boolean true if okey, false if something went wrong.
76
    */
77
    public function callbackSubmit()
78
    {
79
    // Get values from the submitted form
80
81
        $acronym       = $this->form->value("acronym");
82
        $password      = $this->form->value("password");
83
        $passwordAgain = $this->form->value("password-again");
84
        $email         = $this->form->value("email");
85
        $role          = $this->form->value("role");
86
87
        // Check password matches
88
        if ($password !== $passwordAgain) {
89
            $this->form->rememberValues();
90
            $this->form->addOutput("Password did not match.");
91
            return false;
92
        }
93
94
        // Save to database
95
        // $db = $this->di->get("db");
96
        // $password = password_hash($password, PASSWORD_DEFAULT);
97
        // $db->connect()
98
        //    ->insert("User", ["acronym", "password"])
99
        //    ->execute([$acronym, $password]);
100
        $user = new User();
101
        $user->setDb($this->di->get("db"));
102
        $user->acronym = $acronym;
103
        $user->email = $email;
104
        $user->role = $role;
105
        // create gravatar from email
106
        $gravatar = $user->gravatar($email);
107
        $user->gravatar = $gravatar;
108
109
        $user->setPassword($password);
110
        $user->save();
111
112
        $this->form->addOutput("User was created.");
113
        return true;
114
    }
115
}
116

src/User/HTMLForm/EditUserForm.php 1 location

@@ 75-113 (lines=39) @@
72
    *
73
    * @return boolean true if okey, false if something went wrong.
74
    */
75
    public function callbackSubmit()
76
    {
77
    // Get values from the submitted form
78
        $id            = $this->form->value("id");
79
        $acronym       = $this->form->value("acronym");
80
        $password      = $this->form->value("password");
81
        $passwordAgain = $this->form->value("password-again");
82
        $email         = $this->form->value("email");
83
84
        // Check password matches
85
        if ($password !== $passwordAgain) {
86
            $this->form->rememberValues();
87
            $this->form->addOutput("Password did not match.");
88
            return false;
89
        }
90
91
        // Save to database
92
        // $db = $this->di->get("db");
93
        // $password = password_hash($password, PASSWORD_DEFAULT);
94
        // $db->connect()
95
        //    ->insert("User", ["acronym", "password"])
96
        //    ->execute([$acronym, $password]);
97
        $user = new User();
98
        $user->setDb($this->di->get("db"));
99
100
        $user->acronym = $acronym;
101
        $user->email = $email;
102
        $user->id = $id;
103
104
        // create/update gravatar from email
105
        $gravatar = $user->gravatar($email);
106
        $user->gravatar = $gravatar;
107
108
        $user->setPassword($password);
109
        $user->save();
110
111
        $this->form->addOutput("Användarprofil uppdaterades.");
112
        return true;
113
    }
114
}
115