public function indexAction() { return; Star_Http_Response::setBrownerCache(600); $user_service = new UserService(); $user_service->getUserByPage(1, 10); /* $this->openCache('', 0); if ($this->isCache()) { return $this->showCache(); } */ //$this->view->assign('title', 'Hello world!'); //$this->view->setJsConfig(array( // 'files' => array('jquery') //)); echo date('Y-m-d H:i:s'); //$str = "fjakldjflakg'ja'gjqpoigjq;k<>faf<a href=www.baidu.com>www.baidu.com</a>"; //echo Star_Filter::escape($str); //$this->view->assign(array('title' => 'Hello world', 'data' => 'fadjfakl')); //echo date('Y-m-d H:i:s', Star_Date::getLastWeek()); //echo "Hello world"; //$this->view->setNoRender(); //$this->render('hello'); }
public function activateAction($id) { $user_service = new UserService(); $this->response->setNotRender(true); $result = $user_service->activate($id); echo $result; }
public function testAsMember() { $userService = new UserService(); $_SESSION["accountType"] = UserService::$MEMBER; $result = $userService->verifyAccessRight(UserService::$CONTRIBUTOR); $this->assertEquals(false, $result); }
public function initEmail() { $userService = new \UserService(); $this->tempPass = $this->request->getVal('tempPass'); if (empty($this->tempPass)) { $this->tempPass = $userService->resetPassword($this->targetUser); } }
public function get_exchange_record_all($next_id, $count) { $exch_list = $this->exch_table->get_all($next_id, $count); $userSer = new UserService(NULL); foreach ($exch_list as $exch) { $user = $userSer->get_by_uuid($exch->user->uuid); $exch->user = $user; } return $exch_list; }
public function execute() { $expenses = $this->expenseService->getExpenses(array('status=' => Expense::PENDING)); $approvers = $this->userService->getApprovers(); if (count($approvers)) { // Notify of the application $msg = new TemplatedMessage('pending-expenses.php', array('expenses' => $expenses)); $this->notificationService->notifyUser('Pending Expenses', $approvers, $msg); } }
public function testUserCreate() { $userProxy = test::double('User', ['save' => function () { echo "MOCKED User->save() called\n"; }]); $service = new UserService(); $user = $service->createUserByName('Zachary'); $this->assertEquals('Zachary', $user->getName()); $userProxy->verifyInvoked('save'); }
public function indexAction() { //$user_service = new UserService(); $user_service = new UserService(); var_dump($user_service->getUserByPage(1, 1)); $this->view->assign('title', 'Hello world!'); $this->view->setJsConfig(array('files' => array('jquery'))); //$str = "fjakldjflakg'ja'gjqpoigjq;k<>faf<a href=www.baidu.com>www.baidu.com</a>"; //echo Star_Filter::escape($str); //echo date('Y-m-d H:i:s', Star_Date::getLastWeek()); echo "Hello world"; }
/** * Register services related to Users * * @param Application $app */ public function register(Application $app) { $app['user.mapper'] = $app->share(function ($app) { return new UserMapper($app['db'], new UserEntity()); }); $app['user-token.mapper'] = $app->share(function ($app) { return new TokenMapper($app['db'], new TokenEntity()); }); $app['user-role-pivot.mapper'] = $app->share(function ($app) { return new UserRolePivotMapper($app['db']); }); $app['user.service'] = $app->share(function ($app) { $verifyRegistrationView = new VerifyRegistrationView($app['mustache']); $verifyRegistrationView->setUrlGenerator($app['url_generator']); $service = new UserService(); $service->setUserMapper($app['user.mapper'])->setTokenMapper($app['user-token.mapper'])->setEmailService($app['email.service'])->setVerifyRegistrationView($verifyRegistrationView); return $service; }); $app['role.service'] = $app->share(function ($app) { return new RoleService($app['user-role-pivot.mapper']); }); $app['user.validator'] = $app->share(function ($app) { return new UserValidator($app['validator']); }); $app['user-registration.validator'] = $app->share(function ($app) { return new UserRegistrationValidator($app['validator']); }); $app['user.controller'] = $app->share(function ($app) { $controller = new UserController(); $controller->setUserService($app['user.service'])->setUserValidator($app['user.validator'])->setUserRegistrationValidator($app['user-registration.validator']); return $controller; }); $app['user.converter'] = $app->share(function ($app) { return new UserConverter($app['user.mapper']); }); $app['verify-registration.controller'] = $app->share(function ($app) { $controller = new VerifyRegistrationController(); $controller->setUserService($app['user.service']); return $controller; }); $app['reset-password.controller'] = $app->share(function ($app) { $resetPasswordView = new ResetPasswordView($app['mustache']); $resetPasswordView->setUrlGenerator($app['url_generator']); return new ResetPasswordController($app['user.service'], $app['email.service'], $resetPasswordView); }); $app->match('/users', 'user.controller:rest')->method('HEAD|POST')->bind('user-collection'); $app->match('/user', 'user.controller:rest')->method('GET|PUT')->bind('user-entity-self'); $app->match('/users/{user}', 'user.controller:rest')->method('GET')->bind('user-entity')->assert('user', '\\d+')->convert('user', 'user.converter:getUser'); $app->match('/users/{id}/verify-registration', 'verify-registration.controller:rest')->method('POST')->bind('verify-registration'); $app->match('/user/reset-password', 'reset-password.controller:rest')->method('POST|PUT')->bind('reset-password'); $this->setFirewallsAndAccessRules($app); }
private function build_table() { $table_model = new SQLHTMLTableModel(CalendarSetup::$calendar_events_table, 'table', array(new HTMLTableColumn(LangLoader::get_message('form.title', 'common'), 'title'), new HTMLTableColumn(LangLoader::get_message('category', 'categories-common'), 'id_category'), new HTMLTableColumn(LangLoader::get_message('author', 'common'), 'display_name'), new HTMLTableColumn(LangLoader::get_message('date', 'date-common'), 'start_date'), new HTMLTableColumn($this->lang['calendar.titles.repetition']), new HTMLTableColumn(LangLoader::get_message('status.approved', 'common'), 'approved'), new HTMLTableColumn('')), new HTMLTableSortingRule('start_date', HTMLTableSortingRule::DESC)); $table = new HTMLTable($table_model); $table_model->set_caption($this->lang['calendar.config.events.management']); $table_model->add_permanent_filter('parent_id = 0'); $results = array(); $result = $table_model->get_sql_results('event LEFT JOIN ' . CalendarSetup::$calendar_events_content_table . ' event_content ON event_content.id = event.content_id LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = event_content.author_id'); foreach ($result as $row) { $event = new CalendarEvent(); $event->set_properties($row); $category = $event->get_content()->get_category(); $user = $event->get_content()->get_author_user(); $edit_link = new LinkHTMLElement(CalendarUrlBuilder::edit_event(!$event->get_parent_id() ? $event->get_id() : $event->get_parent_id()), '', array('title' => LangLoader::get_message('edit', 'common')), 'fa fa-edit'); $delete_link = new LinkHTMLElement(CalendarUrlBuilder::delete_event($event->get_id()), '', array('title' => LangLoader::get_message('delete', 'common'), 'data-confirmation' => !$event->belongs_to_a_serie() ? 'delete-element' : ''), 'fa fa-delete'); $user_group_color = User::get_group_color($user->get_groups(), $user->get_level(), true); $author = $user->get_id() !== User::VISITOR_LEVEL ? new LinkHTMLElement(UserUrlBuilder::profile($user->get_id()), $user->get_display_name(), !empty($user_group_color) ? array('style' => 'color: ' . $user_group_color) : array(), UserService::get_level_class($user->get_level())) : $user->get_display_name(); $br = new BrHTMLElement(); $results[] = new HTMLTableRow(array(new HTMLTableRowCell(new LinkHTMLElement(CalendarUrlBuilder::display_event($category->get_id(), $category->get_rewrited_name(), $event->get_id(), $event->get_content()->get_rewrited_title()), $event->get_content()->get_title()), 'left'), new HTMLTableRowCell(new SpanHTMLElement($category->get_name(), array('style' => $category->get_id() != Category::ROOT_CATEGORY && $category->get_color() ? 'color:' . $category->get_color() : ''))), new HTMLTableRowCell($author), new HTMLTableRowCell(LangLoader::get_message('from_date', 'main') . ' ' . $event->get_start_date()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE) . $br->display() . LangLoader::get_message('to_date', 'main') . ' ' . $event->get_end_date()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE)), new HTMLTableRowCell($event->belongs_to_a_serie() ? $this->lang['calendar.labels.repeat.' . $event->get_content()->get_repeat_type()] . ' - ' . $event->get_content()->get_repeat_number() . ' ' . $this->lang['calendar.labels.repeat_times'] : LangLoader::get_message('no', 'common')), new HTMLTableRowCell($event->get_content()->is_approved() ? LangLoader::get_message('yes', 'common') : LangLoader::get_message('no', 'common')), new HTMLTableRowCell($edit_link->display() . $delete_link->display()))); } $table->set_rows($table_model->get_number_of_matching_rows(), $results); $this->view->put('table', $table->display()); }
/** * 更新用户信息 */ function update_profile() { $userId = $_SESSION['userId']; $oldPassword = is_empty($_REQUEST['oldPassword']) ? null : $_REQUEST['oldPassword']; $password = is_empty($_REQUEST['password']) ? null : $_REQUEST['password']; $password2 = is_empty($_REQUEST['password2']) ? null : $_REQUEST['password2']; $code = '0'; if ($_SESSION['userDetail']['user_password'] != md5($oldPassword)) { $code = 'wrongOldPassword'; } else { $userService = new UserService(); $userService->updatePassword($userId, md5($password)); } $output = array('retCode' => $code); echo get_json($output); }
/** * Save a contact against a given client object * * * @param array|Contact $params * @return Contact */ public function saveContact($params) { $contact = null; try { $this->dbService->beginTransaction(); // Get an existing one $contact = $this->dbService->saveObject($params, 'Contact'); // check for a user object to also update if ($contact->id) { $user = $this->userService->getUserByField('contactid', $contact->id); if ($user) { $params = array('firstname' => $contact->firstname, 'lastname' => $contact->lastname, 'email' => $contact->email); $this->userService->updateUser($user, $params); } } $this->trackerService->track('update-contact', $contact->id, null, null, print_r($params, true)); $this->dbService->commit(); } catch (Exception $e) { $this->dbService->rollback(); $this->log->err("Failed creating contact for params " . print_r($params, true) . ": " . $e->getMessage()); $contact = null; throw $e; } return $contact; }
/** * Fetch all or a subset of resources * * @param array $params * @return ApiProblem|mixed */ public function fetchAll($params = array()) { if (!$this->userService->isSalesMan()) { return new ApiProblem(415, 'Only admin can see all orders.'); } return $this->orderService->fetchAll(); }
public function run() { $model = new User(User::SCENARIO_LOGIN); // collect user input data if (isset($_REQUEST['User'])) { $model->attributes = $_REQUEST['User']; // validate user input and redirect to previous page if valid if ($model->validate()) { $errorCode = UserService::login($model); switch ($errorCode) { case UserIdentity::ERROR_NONE: $this->returnSuccess(); break; case UserIdentity::ERROR_USERNAME_INVALID: $model->addError('username', Yii::t('user', 'Username is not registered')); break; case UserIdentity::ERROR_PASSWORD_INVALID: $model->addError('password', Yii::t('user', 'Password is not valid')); break; case UserIdentity::ERROR_UNKNOWN_IDENTITY: $model->addError('username', Yii::t('user', 'Unkown identity')); break; } } } $this->returnOrRenderView($model, 'login'); }
private function build_view($request) { $config = BugtrackerConfig::load(); $versions = $config->get_versions(); $display_versions = count($versions); $stats_cache = BugtrackerStatsCache::load(); $bugs_number_per_version = $stats_cache->get_bugs_number_per_version_list(); $top_posters = $stats_cache->get_top_posters_list(); $this->view->put_all(array('C_BUGS' => $stats_cache->get_bugs_number('total'), 'C_FIXED_BUGS' => !empty($bugs_number_per_version), 'C_POSTERS' => !empty($top_posters), 'C_DISPLAY_VERSIONS' => $display_versions, 'C_DISPLAY_TOP_POSTERS' => $config->are_stats_top_posters_enabled(), 'C_ROADMAP_ENABLED' => $config->is_roadmap_enabled())); foreach ($stats_cache->get_bugs_number_list() as $status => $bugs_number) { if ($status != 'total') { $this->view->assign_block_vars('status', array('NAME' => $this->lang['status.' . $status], 'NUMBER' => $bugs_number)); } } foreach ($bugs_number_per_version as $version_id => $bugs_number) { $release_date = !empty($versions[$version_id]['release_date']) && is_numeric($versions[$version_id]['release_date']) ? new Date($versions[$version_id]['release_date'], Timezone::SERVER_TIMEZONE) : null; $this->view->assign_block_vars('fixed_version', array('NAME' => stripslashes($versions[$version_id]['name']), 'RELEASE_DATE' => !empty($release_date) ? $release_date->format(Date::FORMAT_DAY_MONTH_YEAR) : $this->lang['notice.not_defined_e_date'], 'LINK_VERSION_ROADMAP' => BugtrackerUrlBuilder::roadmap($version_id, Url::encode_rewrite($versions[$version_id]['name']))->rel(), 'NUMBER' => $bugs_number['all'])); } foreach ($top_posters as $id => $poster) { if (isset($poster['user'])) { $author_group_color = User::get_group_color($poster['user']->get_groups(), $poster['user']->get_level(), true); $this->view->assign_block_vars('top_poster', array('C_AUTHOR_GROUP_COLOR' => !empty($author_group_color), 'ID' => $id, 'AUTHOR' => $poster['user']->get_display_name(), 'AUTHOR_LEVEL_CLASS' => UserService::get_level_class($poster['user']->get_level()), 'AUTHOR_GROUP_COLOR' => $author_group_color, 'LINK_AUTHOR_PROFILE' => UserUrlBuilder::profile($poster['user']->get_id())->rel(), 'USER_BUGS' => $poster['bugs_number'])); } } return $this->view; }
public function execute(HTTPRequestCustom $request) { $lang = LangLoader::get('common'); $is_admin = AppContext::get_current_user()->check_level(User::ADMIN_LEVEL); $number_admins = UserService::count_admin_members(); $suggestions = array(); try { $result = PersistenceContext::get_querier()->select("SELECT user_id, display_name, level, groups FROM " . DB_TABLE_MEMBER . " WHERE display_name LIKE '" . str_replace('*', '%', $request->get_value('value', '')) . "%'"); while ($row = $result->fetch()) { $user_group_color = User::get_group_color($row['groups'], $row['level']); $suggestion = ''; if ($is_admin) { $edit_link = new LinkHTMLElement(UserUrlBuilder::edit_profile($row['user_id']), '', array('title' => $lang['edit']), 'fa fa-edit'); if ($row['level'] != User::ADMIN_LEVEL || $row['level'] == User::ADMIN_LEVEL && $number_admins > 1) { $delete_link = new LinkHTMLElement(AdminMembersUrlBuilder::delete($row['user_id']), '', array('title' => $lang['delete'], 'data-confirmation' => 'delete-element'), 'fa fa-delete'); } else { $delete_link = new LinkHTMLElement('', '', array('title' => $lang['delete'], 'onclick' => 'return false;'), 'fa fa-delete icon-disabled'); } $suggestion .= $edit_link->display() . ' ' . $delete_link->display() . ' '; } $profile_link = new LinkHTMLElement(UserUrlBuilder::profile($row['user_id'])->rel(), $row['display_name'], array('style' => !empty($user_group_color) ? 'color:' . $user_group_color : ''), UserService::get_level_class($row['level'])); $suggestion .= $profile_link->display(); $suggestions[] = $suggestion; } $result->dispose(); } catch (Exception $e) { } return new JSONResponse(array('suggestions' => $suggestions)); }
/** * Called to redirect after saving a model object * */ protected function onModelSaved($model) { $project = $this->projectService->getProject((int) $this->_getParam('projectid')); // after saving a task, we should probably notify the user about it hey? if (!$this->_getParam('id')) { $message = new TemplatedMessage('new-task.php', array('model' => $model)); $this->notificationService->notifyUser('New task', $model->userid, $message); // Create a watch for the creator $this->notificationService->createWatch(za()->getUser(), $model->id, 'Task'); } // Check to see if the assignee has a watch, if not, add one foreach ($model->userid as $username) { $assignedTo = $this->userService->getByName($username); if ($assignedTo) { $existing = $this->notificationService->getWatch($assignedTo, $model->id, 'Task'); if (!$existing) { $this->notificationService->createWatch($assignedTo, $model->id, 'Task'); } } } if ($this->_getParam('_ajax')) { echo $this->ajaxResponse("Saved " . $model->title); } else { $this->redirect('task', 'edit', array('id' => $model->id)); } }
/** * Create or update a user's account * * @param string $username * @param array $entry */ private function synchroniseUser($entry) { $mapping = ifset($this->config, 'mapping', array()); $username = ifset($entry, $mapping['username'], false); if (!$username) { throw new Exception("No username mapping found."); } // Cast back from the array representation $username = $username[0]; // get all the user's details and map the relevant attributes... which we'll skip! $user = $this->userService->getUserByField('username', $username); if ($user == null) { $params = array(); $params['username'] = $username; $params['password'] = md5(time() . rand(1, 10000)); // Fill in mapped params $email = ifset($entry, $mapping['email'], null); if ($email) { $email = $email[0]; } else { $email = $params['password'] . '@null.com'; } $params['email'] = $email; try { $user = $this->userService->createUser($params, false); } catch (Exception $e) { $this->log->err("Failed creating user for {$username}: " . $e->getMessage() . ': ' . current_url() . "\r\n" . print_r($params, true)); return null; } } za()->log(__CLASS__ . ':' . __LINE__ . " User is " . get_class($user)); return $user; }
private function build_view($group_id) { if (!empty($group_id)) { $group = $this->groups_cache->get_group($group_id); $this->view->put_all(array('C_ADMIN' => AppContext::get_current_user()->check_level(User::ADMIN_LEVEL), 'U_ADMIN_GROUPS' => TPL_PATH_TO_ROOT . '/admin/admin_groups.php?id=' . $group_id, 'GROUP_NAME' => $group['name'])); } else { $this->view->put_all(array('GROUP_NAME' => $this->lang['groups'])); } $user_accounts_config = UserAccountsConfig::load(); $number_member = 0; foreach ($this->get_members_group($group_id) as $user_id) { if (!empty($user_id)) { $user = PersistenceContext::get_querier()->select('SELECT member.display_name, member.level, member.groups, member.warning_percentage, member.delay_banned, ext_field.user_avatar FROM ' . DB_TABLE_MEMBER . ' member LEFT JOIN ' . DB_TABLE_MEMBER_EXTENDED_FIELDS . ' ext_field ON ext_field.user_id = member.user_id WHERE member.user_id = :user_id ', array('user_id' => $user_id))->fetch(); if (!empty($user)) { //Avatar $user_avatar = !empty($user['user_avatar']) ? Url::to_rel($user['user_avatar']) : ($user_accounts_config->is_default_avatar_enabled() ? Url::to_rel('/templates/' . AppContext::get_current_user()->get_theme() . '/images/' . $user_accounts_config->get_default_avatar_name()) : ''); $group_color = User::get_group_color($user['groups'], $user['level']); $this->view->assign_block_vars('members_list', array('C_AVATAR' => $user['user_avatar'] || $user_accounts_config->is_default_avatar_enabled(), 'C_GROUP_COLOR' => !empty($group_color), 'PSEUDO' => $user['display_name'], 'LEVEL' => $user['warning_percentage'] < '100' || time() - $user['delay_banned'] < 0 ? UserService::get_level_lang($user['level']) : $this->lang['banned'], 'LEVEL_CLASS' => UserService::get_level_class($user['level']), 'GROUP_COLOR' => $group_color, 'U_PROFILE' => UserUrlBuilder::profile($user_id)->rel(), 'U_AVATAR' => $user_avatar)); $number_member++; } } } $this->view->put_all(array('C_NOT_MEMBERS' => $number_member == 0, 'SELECT_GROUP' => $this->build_form($group_id)->display())); }
private function build_table() { $table_model = new SQLHTMLTableModel(DownloadSetup::$download_table, 'table', array(new HTMLTableColumn(LangLoader::get_message('form.name', 'common'), 'name'), new HTMLTableColumn(LangLoader::get_message('category', 'categories-common'), 'id_category'), new HTMLTableColumn(LangLoader::get_message('author', 'common'), 'display_name'), new HTMLTableColumn(LangLoader::get_message('form.date.creation', 'common'), 'creation_date'), new HTMLTableColumn(LangLoader::get_message('status', 'common'), 'approbation_type'), new HTMLTableColumn('')), new HTMLTableSortingRule('creation_date', HTMLTableSortingRule::DESC)); $table = new HTMLTable($table_model); $table_model->set_caption($this->lang['download.management']); $results = array(); $result = $table_model->get_sql_results('download LEFT JOIN ' . DB_TABLE_COMMENTS_TOPIC . ' com ON com.id_in_module = download.id AND com.module_id = \'download\' LEFT JOIN ' . DB_TABLE_AVERAGE_NOTES . ' notes ON notes.id_in_module = download.id AND notes.module_name = \'download\' LEFT JOIN ' . DB_TABLE_NOTE . ' note ON note.id_in_module = download.id AND note.module_name = \'download\' AND note.user_id = ' . AppContext::get_current_user()->get_id() . ' LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = download.author_user_id', array('*', 'download.id')); foreach ($result as $row) { $downloadfile = new DownloadFile(); $downloadfile->set_properties($row); $category = $downloadfile->get_category(); $user = $downloadfile->get_author_user(); $edit_link = new LinkHTMLElement(DownloadUrlBuilder::edit($downloadfile->get_id()), '', array('title' => LangLoader::get_message('edit', 'common')), 'fa fa-edit'); $delete_link = new LinkHTMLElement(DownloadUrlBuilder::delete($downloadfile->get_id()), '', array('title' => LangLoader::get_message('delete', 'common'), 'data-confirmation' => 'delete-element'), 'fa fa-delete'); $user_group_color = User::get_group_color($user->get_groups(), $user->get_level(), true); $author = $user->get_id() !== User::VISITOR_LEVEL ? new LinkHTMLElement(UserUrlBuilder::profile($user->get_id()), $user->get_display_name(), !empty($user_group_color) ? array('style' => 'color: ' . $user_group_color) : array(), UserService::get_level_class($user->get_level())) : $user->get_display_name(); $results[] = new HTMLTableRow(array(new HTMLTableRowCell(new LinkHTMLElement(DownloadUrlBuilder::display($category->get_id(), $category->get_rewrited_name(), $downloadfile->get_id(), $downloadfile->get_rewrited_name()), $downloadfile->get_name()), 'left'), new HTMLTableRowCell(new LinkHTMLElement(DownloadUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name()), $category->get_name())), new HTMLTableRowCell($author), new HTMLTableRowCell($downloadfile->get_creation_date()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE)), new HTMLTableRowCell($downloadfile->get_status()), new HTMLTableRowCell($edit_link->display() . $delete_link->display()))); } $table->set_rows($table_model->get_number_of_matching_rows(), $results); $this->view->put('table', $table->display()); }
/** * Get the detailed timesheet for this project. * */ public function detailedtimesheetAction() { $project = $this->projectService->getProject($this->_getParam('projectid')); $client = $this->clientService->getClient($this->_getParam('clientid')); $task = $this->projectService->getTask($this->_getParam('taskid')); $user = $this->userService->getUserByField('username', $this->_getParam('username')); if (!$project && !$client && !$task && !$user) { return; } if ($task) { $this->view->records = $this->projectService->getDetailedTimesheet(null, $task->id); } else { if ($project) { $start = null; $this->view->records = $this->projectService->getDetailedTimesheet(null, null, $project->id); } else { if ($client) { $start = null; $this->view->records = $this->projectService->getDetailedTimesheet(null, null, null, $client->id); } else { if ($user) { $this->view->records = $this->projectService->getDetailedTimesheet($user); } } } } $this->view->task = $task; $this->renderRawView('timesheet/ajax-timesheet-details.php'); }
/** * Notify the user (or users) about something * * @param string $subject * @param array|User $user * @param string $msg */ public function notifyUser($subject, $users, $msg, $from = null, $fromname = null, $html = false) { include_once 'Zend/Mail.php'; if (!is_array($users) && !$users instanceof ArrayAccess) { $users = array($users); } foreach ($users as $u) { if (!$u instanceof NovemberUser) { $this->log->debug("Getting user for " . var_export($u, true)); $u = $this->userService->getUserByField('username', $u); } if ($u == null) { $this->log->debug("Tried sending to non-existent user"); continue; } $mail = new Zend_Mail(); if ($from == null) { $mail->setFrom(za()->getConfig('from_email'), za()->getConfig('name')); } else { if (!$fromname) { $fromname = za()->getConfig('name'); } $mail->setFrom($from, $fromname); } $message = null; if ($msg instanceof TemplatedMessage) { $msg->model['user'] = $u; $message = $this->generateEmail($msg->template, $msg->model); } else { $message = $msg; } if ($html) { $mail->setBodyHtml($message); } else { $mail->setBodyText($message); } $mail->addTo($u->email, $u->username); $mail->setSubject($subject); try { $this->log->debug("Sending message '{$subject}' to " . $u->email); $mail->send(); } catch (Zend_Mail_Transport_Exception $e) { $this->log->debug(__CLASS__ . ':' . __LINE__ . " Failed sending mail: " . $e->getMessage()); throw $e; } } }
public function prepareForEdit($model) { // check the existence of the client to add this contact to $cid = $model->clientid ? $model->clientid : (int) $this->_getParam('clientid'); $client = $this->clientService->getClient($cid); if ($client == null) { $this->flash("Client not found, please update!"); $client = new Client(); } $this->view->title = "Editing Contact"; $this->view->client = $client; $this->view->clients = $this->clientService->getClients(); $this->view->assocUser = null; if ($model->id) { $this->view->assocUser = $this->userService->getUserbyField('contactid', $model->id); } }
public function indexAction() { $name = Request::get('name'); if (!$name) { $name = UserService::getUserName(); } $this->view->set('name', $name); }
/** * @test */ public function it_returns_null_when_a_parse_exception_occurs_when_searching_by_username() { $username = '******'; $query = new \CultureFeed_SearchUsersQuery(); $query->nick = $username; $this->cultureFeed->expects($this->once())->method('searchUsers')->with($query)->willThrowException(new \CultureFeed_ParseException('error')); $user = $this->service->getUserByUsername($username); $this->assertNull($user); }
/** * Prepare a contact for being edited. */ public function prepareForEdit($model) { if ($model == null) { $this->error("Specified contact not found"); return; } // check the existence of the client to add this contact to $cid = $model->clientid ? $model->clientid : (int) $this->_getParam('clientid'); $client = $this->clientService->getClient($cid); if ($client == null) { $this->error("Specified contact not found"); return; } $this->view->title = "Editing Contact"; $this->view->client = $client; $this->view->clients = $this->clientService->getClients(); $this->view->assocUser = $this->userService->getUserbyField('contactid', $model->id); }
public function getUserInfoWithCache($userId) { $data = Yii::app()->cache->get('user-' . $userId); if (empty($data)) { $data = UserService::instance()->getUser($userId); Yii::app()->cache->set('user-' . $userId, $data, 3600 * 24); } return $data; }
/** * Edit a user; requires the user to be logged in and the current password provided * * @param Request $request * @return array */ public function put(Request $request) { $user = $this->getUser(); $userValidationCopy = clone $user; // Validate the modified fields $content = $this->getContentAsArray($request); $errors = $this->userValidator->validate($content, $user); if (count($errors) > 0) { return $this->createConstraintViolationResponse($errors); } $userValidationCopy->exchangeArray($content ?: [])->getArrayCopy(); try { $user = $this->userService->update($user, $this->getContentAsArray($request)); } catch (OutOfBoundsException $e) { return $this->createEmailNotUniqueResponse(); } return $this->userArrayWithoutPassword($user); }
public static function PopulateUserRoleCreateViewModel($userRole) { $model = new UserRoleCreateViewModel(); $model->id = $userRole->userrole_id; $model->user = UserService::GetById($userRole->user_id); $model->role = RoleService::GetById($userRole->role_id); $model->users = UserService::GetAll(); $model->roles = RoleService::GetAll(); return $model; }
function send($mobile, $verify_code) { $userService = new UserService(@$user_id); $mobile_record = $userService->get_by_mobile($mobile, NULL); if ($mobile_record != 1000 && !empty($mobile_record)) { // 查询到有数据 $falg = $userService->del_check_code_by_mobile($mobile); if ($falg) { // true 删除成功 //调用发送手机验证码 $result = MiscUtil::send_mobile($mobile, $verify_code); $status = 0; $message = "发送短信息成功!"; if ($result['data'] == 1) { $userService->add_verify_code($mobile, $result['verify_code']); $json_array = array("status" => $status, "message" => $message); echo json_encode($json_array); } else { $status = 1; $message = "发送短信息失败!"; $json_array = array("status" => $status, "message" => $message); echo json_encode($json_array); } } } else { // 没有查询到数据 //调用发送手机验证码 $result = MiscUtil::send_mobile($mobile, $verify_code); $status = 0; $message = "发送短信息成功!"; if ($result['data'] == 1) { // 插入发送的验证码和电话号码 $userService->add_verify_code($mobile, $result['verify_code']); $json_array = array("status" => $status, "message" => $message); echo json_encode($json_array); } else { $status = 1; $message = "发送短信息失败!"; $json_array = array("status" => $status, "message" => $message); echo json_encode($json_array); } } }