/** * Edit action * * @param string $login */ public function edit_action($id = NULL) { $id or $id = $this->user->id; $user = new User_Object(); $this->db->where('id', $id); if (!$user->find()) { return _404(); } if (!access('user edit_all') && $this->id != $user->id) { return _403(); } $this->renderUserInfo($user); $user = new User_Object(); $user->where('id', $id); $user->find(); $form = new Form('User.profile'); $user->password = ''; $form->object($user->object()); if ($form->elements->avatar->is_ajaxed && Ajax::get('action') == 'replace') { $user->avatar = ''; $user->update(); } if ($result = $form->result()) { if ($user->login != $result['login']) { $redirect = Url::gear('user') . $result['login']; } if ($result->delete && access('users delete_all')) { $user->delete(); flash_success(t('User <b>%s</b> was deleted!')); redirect(Url::link('/users')); } $user->merge($result); if ($result->password) { $user->hashPassword(); } else { unset($user->password); } if ($user->update()) { d('User edit'); flash_success(t('User data saved!'), t('Success')); d(); if ($user->id == $this->id) { $this->store($user->object()->toArray()); } redirect(Url::gear('user') . $user->login); } } append('content', $form->render()); }
/** * Edit action * * @param string $login */ public function edit_action($id = NULL) { $id or $id = $this->user->id; $user = new User_Object(); $user->id = $id; if (!$user->find()) { return event('404'); } $this->hookUserEditMenu($user); // $user->navbar()->show(); $form = new Form('User/forms/profile'); $user->password = ''; $this->input->post('avatar') !== NULL && ($user->object()->avatar = ''); $form->object($user); if ($user->id == 1) { $form->delete->options->render = FALSE; } if ($result = $form->result()) { if ($result->delete && access('User.delete', $user)) { if ($user->delete()) { flash_success(t('Пользователь <b>%s</b> был удалён!', $user->login)); redirect(l('/admin/users')); } } $user->object()->extend($result); if ($result->password) { $user->hashPassword(); } else { unset($user->password); } if ($user->update()) { success(t('Изменения сохранены!')); redirect(l(TRUE)); } } $form->show(); }
/** * Default dispatcher * * @param string $action */ public function index_action($action = '', $subaction = NULL) { if (!empty($_POST['token'])) { // Get the profile of authorized user $UserProfile = $this->api->getAuthInfo($_POST['token']); // Check for errors if (!empty($UserProfile->error_type)) { // Debug info for developer error(t($UserProfile->error_type . ": " . $UserProfile->error_message)); } elseif (empty($UserProfile)) { error(t('Temporary error with Loginza authentification.')); } else { $this->session->loginza = $UserProfile; } } if ($loginza = $this->session->loginza) { /** * There we have 3 ways of workflow * * 1. User is logged in. Add new identity to database if it's not exist. * 2. User is registred. Authorize. * 3. User is not registred. Show register form connected and fullfilled with Loginza data (login, e-mail and so on). */ $user = new Db_ORM('users_loginza'); $user->identity = $loginza->identity; // If user is logged in if ($this->user->id) { // If integration is found if ($user->find()) { // If integration belongs to the current user if ($user->uid == $this->user->id) { $user->loginza->data = json_encode($loginza); $user->update(); flash_info(t('Your integration with profile <b>%s</b> was updated successfully.', 'Loginza', $loginza->identity), t('Updated succeed.')); } else { flash_error(t('Profile <b>%s</b> is integrated with sombody else account. You cannot use it before someone would left it out.', 'Loginza', $loginza->identity), t('Update failure.')); } } else { // Create new database record $user->uid = $this->user->id; $user->provider = $loginza->provider; $UserProfile = new Loginza_UserProfile($loginza); isset($loginza->photo) && ($user->photo = $loginza->photo); $user->full_name = $UserProfile->genFullName(); $user->data = json_encode($loginza); $user->save(); } $this->session->loginza = NULL; // Redirect to user profile redirect(Url::gear('user') . 'edit/#tab-social'); } else { // Record found → try to log in if ($user->find()) { $search = new User_Object(); $search->id = $user->uid; if ($search->find()) { $this->user->forceLogin($user->uid, 'id'); } else { flash_error(t('Cannot find user with id <b>%s</b>.', 'Loginza', $user->uid)); } $this->session->loginza = NULL; // This tiny little redirect caused error by Loginza "Invalid / empty session data! Retry auth.: // Left it where it is for memories. // Important! Do not uncomment! //back(); } else { if (!access('user register')) { return info('You don\'t have an access to registration'); } success('First step of registration is done. Please, fill some fields to complete your registration.'); $form = new Form('User.register'); $UserProfile = new Loginza_UserProfile($loginza); $tpl = new Template('Loginza.register'); $tpl->loginza = $loginza; $tpl->profile = $UserProfile; append('content', $tpl->render()); $data['login'] = $UserProfile->genFullName(); isset($loginza->email) && ($data['email'] = $loginza->email); $form->setValues($data); if ($data = $form->result()) { $this->user->object($data); $this->user->hashPassword(); if ($uid = $this->user->save()) { // Create new database record $user->uid = $uid; $user->provider = $loginza->provider; $UserProfile = new Loginza_UserProfile($loginza); isset($loginza->photo) && ($user->photo = $loginza->photo); $user->full_name = $UserProfile->genFullName(); $user->data = json_encode($loginza); $user->save(); } $this->session->loginza = NULL; flash_success('User was successfully registered! Please, check your email for further instructions.', 'Registration succeed.'); redirect(); } append('content', $form->render()); } } } }