public function signup($post_data) { $user = new Users(); $user->username = $post_data['username']; $user->username_rus = $post_data['runame']; $user->pasport_code = (int) $post_data['passport_code']; $user->ref_id = $post_data['user_ref_id']; $user->password = Yii::$app->getSecurity()->generatePasswordHash($post_data['password']); $user->social_role = 'N'; $user->ip = $_SERVER['REMOTE_ADDR']; $this->photo = UploadedFile::getInstanceByName('userfile'); if ($this->photo) { $user->avatar = $this->photo->baseName . '.' . $this->photo->extension; } if ($user->save()) { if ($this->photo) { mkdir('./images/users_photo/' . $user->id . '/avatar/', 0777, true); // chmod('./images/users_photo/' . $user->id, 0777); // chmod('./images/users_photo/' . $user->id . '/avatar/', 0777); $this->photo->saveAs('images/users_photo/' . $user->id . '/avatar/' . $this->photo->baseName . '.' . $this->photo->extension); } if (Yii::$app->session->has('guest')) { $guest = Yii::$app->session->get('guest'); UsersParameters::syncFromGuestsParameters($user->id, $guest->id); UsersStats::syncFromGuestsStats($user->id, $guest->id); Yii::$app->session->remove('guest'); } Yii::$app->user->login($user, 3600 * 24 * 30); return true; } else { return false; } }
public static function add($username, $password, $org_id) { $cashier = new Users(); $cashier->social_role = self::SOCIAL_ROLE; $cashier->username = $username; $cashier->password = $password; $cashier->pasport_code = Users::getPassportCode(self::SOCIAL_ROLE); if ($cashier->save()) { $cashier_org_relation = new OrganizationsCashiers(); $cashier_org_relation->user_id = $cashier->id; $cashier_org_relation->organization_id = $org_id; return $cashier_org_relation->save(); } return false; }