当前位置: 首页>>代码示例>>PHP>>正文


PHP AphrontErrorView::setErrors方法代码示例

本文整理汇总了PHP中AphrontErrorView::setErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP AphrontErrorView::setErrors方法的具体用法?PHP AphrontErrorView::setErrors怎么用?PHP AphrontErrorView::setErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AphrontErrorView的用法示例。


在下文中一共展示了AphrontErrorView::setErrors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processRequest

 public function processRequest()
 {
     if ($this->id) {
         $macro = id(new PhabricatorFileImageMacro())->load($this->id);
         if (!$macro) {
             return new Aphront404Response();
         }
     } else {
         $macro = new PhabricatorFileImageMacro();
     }
     $errors = array();
     $e_name = true;
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($request->isFormPost()) {
         $macro->setName($request->getStr('name'));
         if (!strlen($macro->getName())) {
             $errors[] = 'Macro name is required.';
             $e_name = 'Required';
         } else {
             if (!preg_match('/^[a-z0-9_-]{3,}$/', $macro->getName())) {
                 $errors[] = 'Macro must be at least three characters long and contain ' . 'only lowercase letters, digits, hyphen and underscore.';
                 $e_name = 'Invalid';
             } else {
                 $e_name = null;
             }
         }
         if (!$errors) {
             $file = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'file'), array('name' => $request->getStr('name'), 'authorPHID' => $user->getPHID()));
             $macro->setFilePHID($file->getPHID());
             try {
                 $macro->save();
                 return id(new AphrontRedirectResponse())->setURI('/file/macro/');
             } catch (AphrontQueryDuplicateKeyException $ex) {
                 $errors[] = 'Macro name is not unique!';
                 $e_name = 'Duplicate';
             }
         }
     }
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Form Errors');
         $error_view->setErrors($errors);
     } else {
         $error_view = null;
     }
     $form = new AphrontFormView();
     $form->setAction('/file/macro/edit/');
     $form->setUser($request->getUser());
     $form->setEncType('multipart/form-data')->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($macro->getName())->setCaption('This word or phrase will be replaced with the image.')->setError($e_name))->appendChild(id(new AphrontFormFileControl())->setLabel('File')->setName('file')->setError(true))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save Image Macro')->addCancelButton('/file/macro/'));
     $panel = new AphrontPanelView();
     if ($macro->getID()) {
         $panel->setHeader('Edit Image Macro');
     } else {
         $panel->setHeader('Create Image Macro');
     }
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Image Macro'));
 }
开发者ID:nguyennamtien,项目名称:phabricator,代码行数:60,代码来源:PhabricatorFileMacroEditController.php

示例2: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $editable = $this->getAccountEditable();
     // There's no sense in showing a change password panel if the user
     // can't change their password
     if (!$editable || !PhabricatorEnv::getEnvConfig('auth.password-auth-enabled')) {
         return new Aphront400Response();
     }
     $errors = array();
     if ($request->isFormPost()) {
         if ($user->comparePassword($request->getStr('old_pw'))) {
             $pass = $request->getStr('new_pw');
             $conf = $request->getStr('conf_pw');
             if ($pass === $conf) {
                 if (strlen($pass)) {
                     $user->setPassword($pass);
                     // This write is unguarded because the CSRF token has already
                     // been checked in the call to $request->isFormPost() and
                     // the CSRF token depends on the password hash, so when it
                     // is changed here the CSRF token check will fail.
                     $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
                     $user->save();
                     unset($unguarded);
                     return id(new AphrontRedirectResponse())->setURI('/settings/page/password/?saved=true');
                 } else {
                     $errors[] = 'Your new password is too short.';
                 }
             } else {
                 $errors[] = 'New password and confirmation do not match.';
             }
         } else {
             $errors[] = 'The old password you entered is incorrect.';
         }
     }
     $notice = null;
     if (!$errors) {
         if ($request->getStr('saved')) {
             $notice = new AphrontErrorView();
             $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
             $notice->setTitle('Changes Saved');
             $notice->appendChild('<p>Your password has been updated.</p>');
         }
     } else {
         $notice = new AphrontErrorView();
         $notice->setTitle('Error Changing Password');
         $notice->setErrors($errors);
     }
     $form = new AphrontFormView();
     $form->setUser($user)->appendChild(id(new AphrontFormPasswordControl())->setLabel('Old Password')->setName('old_pw'));
     $form->appendChild(id(new AphrontFormPasswordControl())->setLabel('New Password')->setName('new_pw'));
     $form->appendChild(id(new AphrontFormPasswordControl())->setLabel('Confirm Password')->setName('conf_pw'));
     $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Save'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Change Password');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild($form);
     return id(new AphrontNullView())->appendChild(array($notice, $panel));
 }
开发者ID:hwang36,项目名称:phabricator,代码行数:60,代码来源:PhabricatorUserPasswordSettingsPanelController.php

示例3: processImportRequest

 private function processImportRequest($request)
 {
     $admin = $request->getUser();
     $usernames = $request->getArr('usernames');
     $emails = $request->getArr('email');
     $names = $request->getArr('name');
     $notice_view = new AphrontErrorView();
     $notice_view->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
     $notice_view->setTitle(pht('Import Successful'));
     $notice_view->setErrors(array(pht('Successfully imported users from LDAP')));
     $list = new PHUIObjectItemListView();
     $list->setNoDataString(pht('No users imported?'));
     foreach ($usernames as $username) {
         $user = new PhabricatorUser();
         $user->setUsername($username);
         $user->setRealname($names[$username]);
         $email_obj = id(new PhabricatorUserEmail())->setAddress($emails[$username])->setIsVerified(1);
         try {
             id(new PhabricatorUserEditor())->setActor($admin)->createNewUser($user, $email_obj);
             id(new PhabricatorExternalAccount())->setUserPHID($user->getPHID())->setAccountType('ldap')->setAccountDomain('self')->setAccountID($username)->save();
             $header = pht('Successfully added %s', $username);
             $attribute = null;
             $color = 'green';
         } catch (Exception $ex) {
             $header = pht('Failed to add %s', $username);
             $attribute = $ex->getMessage();
             $color = 'red';
         }
         $item = id(new PHUIObjectItemView())->setHeader($header)->addAttribute($attribute)->setBarColor($color);
         $list->addItem($item);
     }
     return array($notice_view, $list);
 }
开发者ID:denghp,项目名称:phabricator,代码行数:33,代码来源:PhabricatorPeopleLdapController.php

示例4: renderErrorPage

 protected function renderErrorPage($title, array $messages)
 {
     $view = new AphrontErrorView();
     $view->setTitle($title);
     $view->setErrors($messages);
     return $this->buildApplicationPage($view, array('title' => $title));
 }
开发者ID:denghp,项目名称:phabricator,代码行数:7,代码来源:PhabricatorAuthController.php

示例5: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $project = new PhabricatorProject();
     $project->setAuthorPHID($user->getPHID());
     $profile = new PhabricatorProjectProfile();
     $e_name = true;
     $errors = array();
     if ($request->isFormPost()) {
         try {
             $editor = new PhabricatorProjectEditor($project);
             $editor->setUser($user);
             $editor->setName($request->getStr('name'));
             $editor->save();
         } catch (PhabricatorProjectNameCollisionException $ex) {
             $e_name = 'Not Unique';
             $errors[] = $ex->getMessage();
         }
         $project->setStatus(PhabricatorProjectStatus::ONGOING);
         $profile->setBlurb($request->getStr('blurb'));
         if (!$errors) {
             $project->save();
             $profile->setProjectPHID($project->getPHID());
             $profile->save();
             id(new PhabricatorProjectAffiliation())->setUserPHID($user->getPHID())->setProjectPHID($project->getPHID())->setRole('Owner')->setIsOwner(true)->save();
             if ($request->isAjax()) {
                 return id(new AphrontAjaxResponse())->setContent(array('phid' => $project->getPHID(), 'name' => $project->getName()));
             } else {
                 return id(new AphrontRedirectResponse())->setURI('/project/view/' . $project->getID() . '/');
             }
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Form Errors');
         $error_view->setErrors($errors);
     }
     if ($request->isAjax()) {
         $form = new AphrontFormLayoutView();
     } else {
         $form = new AphrontFormView();
         $form->setUser($user);
     }
     $form->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($project->getName())->setError($e_name))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Blurb')->setName('blurb')->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)->setValue($profile->getBlurb()));
     if ($request->isAjax()) {
         if ($error_view) {
             $error_view->setWidth(AphrontErrorView::WIDTH_DIALOG);
         }
         $dialog = id(new AphrontDialogView())->setUser($user)->setWidth(AphrontDialogView::WIDTH_FORM)->setTitle('Create a New Project')->appendChild($error_view)->appendChild($form)->addSubmitButton('Create Project')->addCancelButton('/project/');
         return id(new AphrontDialogResponse())->setDialog($dialog);
     } else {
         $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Create')->addCancelButton('/project/'));
         $panel = new AphrontPanelView();
         $panel->setWidth(AphrontPanelView::WIDTH_FORM)->setHeader('Create a New Project')->appendChild($form);
         return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Create new Project'));
     }
 }
开发者ID:netcomtec,项目名称:phabricator,代码行数:59,代码来源:PhabricatorProjectCreateController.php

示例6: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $resource = new DrydockResource();
     $json = new PhutilJSON();
     $err_attributes = true;
     $err_capabilities = true;
     $json_attributes = $json->encodeFormatted($resource->getAttributes());
     $json_capabilities = $json->encodeFormatted($resource->getCapabilities());
     $errors = array();
     if ($request->isFormPost()) {
         $raw_attributes = $request->getStr('attributes');
         $attributes = json_decode($raw_attributes, true);
         if (!is_array($attributes)) {
             $err_attributes = 'Invalid';
             $errors[] = 'Enter attributes as a valid JSON object.';
             $json_attributes = $raw_attributes;
         } else {
             $resource->setAttributes($attributes);
             $json_attributes = $json->encodeFormatted($attributes);
             $err_attributes = null;
         }
         $raw_capabilities = $request->getStr('capabilities');
         $capabilities = json_decode($raw_capabilities, true);
         if (!is_array($capabilities)) {
             $err_capabilities = 'Invalid';
             $errors[] = 'Enter capabilities as a valid JSON object.';
             $json_capabilities = $raw_capabilities;
         } else {
             $resource->setCapabilities($capabilities);
             $json_capabilities = $json->encodeFormatted($capabilities);
             $err_capabilities = null;
         }
         $resource->setBlueprintClass($request->getStr('blueprint'));
         $resource->setType($resource->getBlueprint()->getType());
         $resource->setOwnerPHID($user->getPHID());
         $resource->setName($request->getStr('name'));
         if (!$errors) {
             $resource->save();
             return id(new AphrontRedirectResponse())->setURI('/drydock/resource/');
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Form Errors');
         $error_view->setErrors($errors);
     }
     $blueprints = id(new PhutilSymbolLoader())->setType('class')->setAncestorClass('DrydockBlueprint')->selectAndLoadSymbols();
     $blueprints = ipull($blueprints, 'name', 'name');
     $panel = new AphrontPanelView();
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->setHeader('Allocate Drydock Resource');
     $form = id(new AphrontFormView())->setUser($request->getUser())->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($resource->getName()))->appendChild(id(new AphrontFormSelectControl())->setLabel('Blueprint')->setOptions($blueprints)->setName('blueprint')->setValue($resource->getBlueprintClass()))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Attributes')->setName('attributes')->setValue($json_attributes)->setError($err_attributes)->setCaption('Specify attributes in JSON.'))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Capabilities')->setName('capabilities')->setValue($json_capabilities)->setError($err_capabilities)->setCaption('Specify capabilities in JSON.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Allocate Resource'));
     $panel->appendChild($form);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Allocate Resource'));
 }
开发者ID:nexeck,项目名称:phabricator,代码行数:58,代码来源:DrydockResourceAllocateController.php

示例7: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $e_name = true;
     $e_callsign = true;
     $repository = new PhabricatorRepository();
     $type_map = PhabricatorRepositoryType::getAllRepositoryTypes();
     $errors = array();
     if ($request->isFormPost()) {
         $repository->setName($request->getStr('name'));
         $repository->setCallsign($request->getStr('callsign'));
         $repository->setVersionControlSystem($request->getStr('type'));
         if (!strlen($repository->getName())) {
             $e_name = 'Required';
             $errors[] = 'Repository name is required.';
         } else {
             $e_name = null;
         }
         if (!strlen($repository->getCallsign())) {
             $e_callsign = 'Required';
             $errors[] = 'Callsign is required.';
         } else {
             if (!preg_match('/^[A-Z]+$/', $repository->getCallsign())) {
                 $e_callsign = 'Invalid';
                 $errors[] = 'Callsign must be ALL UPPERCASE LETTERS.';
             } else {
                 $e_callsign = null;
             }
         }
         if (empty($type_map[$repository->getVersionControlSystem()])) {
             $errors[] = 'Invalid version control system.';
         }
         if (!$errors) {
             try {
                 $repository->save();
                 return id(new AphrontRedirectResponse())->setURI('/repository/edit/' . $repository->getID() . '/');
             } catch (AphrontQueryDuplicateKeyException $ex) {
                 $e_callsign = 'Duplicate';
                 $errors[] = 'Callsign must be unique. Another repository already ' . 'uses that callsign.';
             }
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setErrors($errors);
         $error_view->setTitle('Form Errors');
     }
     $form = new AphrontFormView();
     $form->setUser($user)->setAction('/repository/create/')->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($repository->getName())->setError($e_name)->setCaption('Human-readable repository name.'))->appendChild('<p class="aphront-form-instructions">Select a "Callsign" &mdash; a ' . 'short, uppercase string to identify revisions in this repository. If ' . 'you choose "EX", revisions in this repository will be identified ' . 'with the prefix "rEX".</p>')->appendChild(id(new AphrontFormTextControl())->setLabel('Callsign')->setName('callsign')->setValue($repository->getCallsign())->setError($e_callsign)->setCaption('Short, UPPERCASE identifier. Once set, it can not be changed.'))->appendChild(id(new AphrontFormSelectControl())->setLabel('Type')->setName('type')->setOptions($type_map)->setValue($repository->getVersionControlSystem()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Create Repository')->addCancelButton('/repository/'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Create Repository');
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Create Repository'));
 }
开发者ID:nexeck,项目名称:phabricator,代码行数:57,代码来源:PhabricatorRepositoryCreateController.php

示例8: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     if (!PhabricatorEnv::getEnvConfig('auth.password-auth-enabled')) {
         return new Aphront400Response();
     }
     $token = $this->token;
     $email = $request->getStr('email');
     $target_user = id(new PhabricatorUser())->loadOneWhere('email = %s', $email);
     if (!$target_user || !$target_user->validateEmailToken($token)) {
         $view = new AphrontRequestFailureView();
         $view->setHeader('Unable to Login');
         $view->appendChild('<p>The authentication information in the link you clicked is ' . 'invalid or out of date. Make sure you are copy-and-pasting the ' . 'entire link into your browser. You can try again, or request ' . 'a new email.</p>');
         $view->appendChild('<div class="aphront-failure-continue">' . '<a class="button" href="/login/email/">Send Another Email</a>' . '</div>');
         return $this->buildStandardPageResponse($view, array('title' => 'Email Sent'));
     }
     if ($request->getUser()->getPHID() != $target_user->getPHID()) {
         $session_key = $target_user->establishSession('web');
         $request->setCookie('phusr', $target_user->getUsername());
         $request->setCookie('phsid', $session_key);
     }
     $errors = array();
     $e_pass = true;
     $e_confirm = true;
     if ($request->isFormPost()) {
         $e_pass = 'Error';
         $e_confirm = 'Error';
         $pass = $request->getStr('password');
         $confirm = $request->getStr('confirm');
         if (strlen($pass) < 3) {
             $errors[] = 'That password is ridiculously short.';
         }
         if ($pass !== $confirm) {
             $errors[] = "Passwords do not match.";
         }
         if (!$errors) {
             $target_user->setPassword($pass);
             $target_user->save();
             return id(new AphrontRedirectResponse())->setURI('/');
         }
     }
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Password Reset Failed');
         $error_view->setErrors($errors);
     } else {
         $error_view = null;
     }
     $form = new AphrontFormView();
     $form->setUser($target_user)->setAction('/login/etoken/' . $token . '/')->addHiddenInput('email', $email)->appendChild(id(new AphrontFormPasswordControl())->setLabel('New Password')->setName('password')->setError($e_pass))->appendChild(id(new AphrontFormPasswordControl())->setLabel('Confirm Password')->setName('confirm')->setError($e_confirm))->appendChild(id(new AphrontFormSubmitControl())->setValue('Reset Password')->addCancelButton('/', 'Skip'));
     $panel = new AphrontPanelView();
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->setHeader('Reset Password');
     $panel->appendChild($form);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Create New Account'));
 }
开发者ID:nguyennamtien,项目名称:phabricator,代码行数:56,代码来源:PhabricatorEmailTokenController.php

示例9: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $editable = $this->getAccountEditable();
     $e_realname = $editable ? true : null;
     $errors = array();
     if ($request->isFormPost()) {
         if ($editable) {
             $user->setRealName($request->getStr('realname'));
             if (!strlen($user->getRealName())) {
                 $errors[] = 'Real name must be nonempty.';
                 $e_realname = 'Required';
             }
         }
         $new_timezone = $request->getStr('timezone');
         if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) {
             $user->setTimezoneIdentifier($new_timezone);
         } else {
             $errors[] = 'The selected timezone is not a valid timezone.';
         }
         if (!$errors) {
             $user->save();
             return id(new AphrontRedirectResponse())->setURI('/settings/page/account/?saved=true');
         }
     }
     $notice = null;
     if (!$errors) {
         if ($request->getStr('saved')) {
             $notice = new AphrontErrorView();
             $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
             $notice->setTitle('Changes Saved');
             $notice->appendChild('<p>Your changes have been saved.</p>');
             $notice = $notice->render();
         }
     } else {
         $notice = new AphrontErrorView();
         $notice->setTitle('Form Errors');
         $notice->setErrors($errors);
         $notice = $notice->render();
     }
     $timezone_ids = DateTimeZone::listIdentifiers();
     $timezone_id_map = array_combine($timezone_ids, $timezone_ids);
     $form = new AphrontFormView();
     $form->setUser($user)->setEncType('multipart/form-data')->appendChild(id(new AphrontFormStaticControl())->setLabel('Username')->setValue($user->getUsername()))->appendChild(id(new AphrontFormTextControl())->setLabel('Real Name')->setName('realname')->setError($e_realname)->setValue($user->getRealName())->setDisabled(!$editable))->appendChild(id(new AphrontFormSelectControl())->setLabel('Timezone')->setName('timezone')->setOptions($timezone_id_map)->setValue($user->getTimezoneIdentifier()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Account Settings');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild($form);
     return id(new AphrontNullView())->appendChild(array($notice, $panel));
 }
开发者ID:nexeck,项目名称:phabricator,代码行数:51,代码来源:PhabricatorUserAccountSettingsPanelController.php

示例10: renderExample

 public function renderExample()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $sevs = array(AphrontErrorView::SEVERITY_ERROR => 'Error', AphrontErrorView::SEVERITY_WARNING => 'Warning', AphrontErrorView::SEVERITY_NOTICE => 'Notice', AphrontErrorView::SEVERITY_NODATA => 'No Data');
     $views = array();
     foreach ($sevs as $sev => $title) {
         $view = new AphrontErrorView();
         $view->setSeverity($sev);
         $view->setTitle($title);
         $view->appendChild('Several issues were encountered.');
         $view->setErrors(array('Overcooked.', 'Too much salt.', 'Full of sand.'));
         $views[] = $view;
     }
     return $views;
 }
开发者ID:denghp,项目名称:phabricator,代码行数:16,代码来源:PhabricatorErrorExample.php

示例11: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $editable = $this->getAccountEditable();
     $e_email = true;
     $errors = array();
     if ($request->isFormPost()) {
         if (!$editable) {
             return new Aphront400Response();
         }
         $user->setEmail($request->getStr('email'));
         if (!strlen($user->getEmail())) {
             $errors[] = 'You must enter an e-mail address.';
             $e_email = 'Required';
         }
         if (!$errors) {
             $user->save();
             return id(new AphrontRedirectResponse())->setURI('/settings/page/email/?saved=true');
         }
     }
     $notice = null;
     if (!$errors) {
         if ($request->getStr('saved')) {
             $notice = new AphrontErrorView();
             $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
             $notice->setTitle('Changes Saved');
             $notice->appendChild('<p>Your changes have been saved.</p>');
         }
     } else {
         $notice = new AphrontErrorView();
         $notice->setTitle('Form Errors');
         $notice->setErrors($errors);
     }
     $form = new AphrontFormView();
     $form->setUser($user)->appendChild(id(new AphrontFormTextControl())->setLabel('Email')->setName('email')->setDisabled(!$editable)->setCaption('Note: there is no email validation yet; double-check your ' . 'typing.')->setValue($user->getEmail())->setError($e_email));
     if ($editable) {
         $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Save'));
     }
     $panel = new AphrontPanelView();
     $panel->setHeader('Email Settings');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild($form);
     return id(new AphrontNullView())->appendChild(array($notice, $panel));
 }
开发者ID:nguyennamtien,项目名称:phabricator,代码行数:45,代码来源:PhabricatorUserEmailSettingsPanelController.php

示例12: processRequest


//.........这里部分代码省略.........
                     $task->setPriority($template_task->getPriority());
                     $task->setViewPolicy($template_task->getViewPolicy());
                     $task->setEditPolicy($template_task->getEditPolicy());
                     $template_fields = PhabricatorCustomField::getObjectFields($template_task, PhabricatorCustomField::ROLE_EDIT);
                     $fields = $template_fields->getFields();
                     foreach ($fields as $key => $field) {
                         if (!$field->shouldCopyWhenCreatingSimilarTask()) {
                             unset($fields[$key]);
                         }
                         if (empty($aux_fields[$key])) {
                             unset($fields[$key]);
                         }
                     }
                     if ($fields) {
                         id(new PhabricatorCustomFieldList($fields))->setViewer($user)->readFieldsFromStorage($template_task);
                         foreach ($fields as $key => $field) {
                             $aux_fields[$key]->setValueFromStorage($field->getValueForStorage());
                         }
                     }
                 }
             }
         }
     }
     $phids = array_merge(array($task->getOwnerPHID()), $task->getCCPHIDs(), $task->getProjectPHIDs());
     if ($parent_task) {
         $phids[] = $parent_task->getPHID();
     }
     $phids = array_filter($phids);
     $phids = array_unique($phids);
     $handles = $this->loadViewerHandles($phids);
     $error_view = null;
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setErrors($errors);
     }
     $priority_map = ManiphestTaskPriority::getTaskPriorityMap();
     if ($task->getOwnerPHID()) {
         $assigned_value = array($handles[$task->getOwnerPHID()]);
     } else {
         $assigned_value = array();
     }
     if ($task->getCCPHIDs()) {
         $cc_value = array_select_keys($handles, $task->getCCPHIDs());
     } else {
         $cc_value = array();
     }
     if ($task->getProjectPHIDs()) {
         $projects_value = array_select_keys($handles, $task->getProjectPHIDs());
     } else {
         $projects_value = array();
     }
     $cancel_id = nonempty($task->getID(), $template_id);
     if ($cancel_id) {
         $cancel_uri = '/T' . $cancel_id;
     } else {
         $cancel_uri = '/maniphest/';
     }
     if ($task->getID()) {
         $button_name = pht('Save Task');
         $header_name = pht('Edit Task');
     } else {
         if ($parent_task) {
             $cancel_uri = '/T' . $parent_task->getID();
             $button_name = pht('Create Task');
             $header_name = pht('Create New Subtask');
         } else {
开发者ID:denghp,项目名称:phabricator,代码行数:67,代码来源:ManiphestTaskEditController.php

示例13: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($this->id) {
         $package = id(new PhabricatorOwnersPackage())->load($this->id);
         if (!$package) {
             return new Aphront404Response();
         }
     } else {
         $package = new PhabricatorOwnersPackage();
         $package->setPrimaryOwnerPHID($user->getPHID());
     }
     $e_name = true;
     $e_primary = true;
     $e_owners = true;
     $errors = array();
     if ($request->isFormPost()) {
         $package->setName($request->getStr('name'));
         $package->setDescription($request->getStr('description'));
         $primary = $request->getArr('primary');
         $primary = reset($primary);
         $package->setPrimaryOwnerPHID($primary);
         $owners = $request->getArr('owners');
         if ($primary) {
             array_unshift($owners, $primary);
         }
         $owners = array_unique($owners);
         $paths = $request->getArr('path');
         $repos = $request->getArr('repo');
         $path_refs = array();
         for ($ii = 0; $ii < count($paths); $ii++) {
             if (empty($paths[$ii]) || empty($repos[$ii])) {
                 continue;
             }
             $path_refs[] = array('repositoryPHID' => $repos[$ii], 'path' => $paths[$ii]);
         }
         if (!strlen($package->getName())) {
             $e_name = 'Required';
             $errors[] = 'Package name is required.';
         } else {
             $e_name = null;
         }
         if (!$package->getPrimaryOwnerPHID()) {
             $e_primary = 'Required';
             $errors[] = 'Package must have a primary owner.';
         } else {
             $e_primary = null;
         }
         if (!$owners) {
             $e_owners = 'Required';
             $errors[] = 'Package must have at least one owner.';
         } else {
             $e_owners = null;
         }
         if (!$path_refs) {
             $errors[] = 'Package must include at least one path.';
         }
         if (!$errors) {
             $package->attachUnsavedOwners($owners);
             $package->attachUnsavedPaths($path_refs);
             try {
                 $package->save();
                 return id(new AphrontRedirectResponse())->setURI('/owners/package/' . $package->getID() . '/');
             } catch (AphrontQueryDuplicateKeyException $ex) {
                 $e_name = 'Duplicate';
                 $errors[] = 'Package name must be unique.';
             }
         }
     } else {
         $owners = $package->loadOwners();
         $owners = mpull($owners, 'getUserPHID');
         $paths = $package->loadPaths();
         $path_refs = array();
         foreach ($paths as $path) {
             $path_refs[] = array('repositoryPHID' => $path->getRepositoryPHID(), 'path' => $path->getPath());
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Package Errors');
         $error_view->setErrors($errors);
     }
     $handles = id(new PhabricatorObjectHandleData($owners))->loadHandles();
     $primary = $package->getPrimaryOwnerPHID();
     if ($primary && isset($handles[$primary])) {
         $token_primary_owner = array($primary => $handles[$primary]->getFullName());
     } else {
         $token_primary_owner = array();
     }
     $token_all_owners = array_select_keys($handles, $owners);
     $token_all_owners = mpull($token_all_owners, 'getFullName');
     $title = $package->getID() ? 'Edit Package' : 'New Package';
     $repos = id(new PhabricatorRepository())->loadAll();
     $default_paths = array();
     foreach ($repos as $repo) {
         $default_path = $repo->getDetail('default-owners-path');
         if ($default_path) {
             $default_paths[$repo->getPHID()] = $default_path;
//.........这里部分代码省略.........
开发者ID:nguyennamtien,项目名称:phabricator,代码行数:101,代码来源:PhabricatorOwnersEditController.php

示例14: processRequest

 public function processRequest()
 {
     if (!$this->provider->isProviderEnabled()) {
         return new Aphront400Response();
     }
     $current_user = $this->getRequest()->getUser();
     $request = $this->getRequest();
     $ldap_username = $request->getCookie('phusr');
     if ($request->isFormPost()) {
         $ldap_username = $request->getStr('username');
         try {
             $envelope = new PhutilOpaqueEnvelope($request->getStr('password'));
             $this->provider->auth($ldap_username, $envelope);
         } catch (Exception $e) {
             $errors[] = $e->getMessage();
         }
         if (empty($errors)) {
             $ldap_info = $this->retrieveLDAPInfo($this->provider);
             if ($current_user->getPHID()) {
                 if ($ldap_info->getID()) {
                     $existing_ldap = id(new PhabricatorUserLDAPInfo())->loadOneWhere('userID = %d', $current_user->getID());
                     if ($ldap_info->getUserID() != $current_user->getID() || $existing_ldap) {
                         $dialog = new AphrontDialogView();
                         $dialog->setUser($current_user);
                         $dialog->setTitle('Already Linked to Another Account');
                         $dialog->appendChild('<p>The LDAP account you just authorized is already linked to ' . 'another Phabricator account. Before you can link it to a ' . 'different LDAP account, you must unlink the old account.</p>');
                         $dialog->addCancelButton('/settings/page/ldap/');
                         return id(new AphrontDialogResponse())->setDialog($dialog);
                     } else {
                         return id(new AphrontRedirectResponse())->setURI('/settings/page/ldap/');
                     }
                 }
                 if (!$request->isDialogFormPost()) {
                     $dialog = new AphrontDialogView();
                     $dialog->setUser($current_user);
                     $dialog->setTitle('Link LDAP Account');
                     $dialog->appendChild('<p>Link your LDAP account to your Phabricator account?</p>');
                     $dialog->addHiddenInput('username', $request->getStr('username'));
                     $dialog->addHiddenInput('password', $request->getStr('password'));
                     $dialog->addSubmitButton('Link Accounts');
                     $dialog->addCancelButton('/settings/page/ldap/');
                     return id(new AphrontDialogResponse())->setDialog($dialog);
                 }
                 $ldap_info->setUserID($current_user->getID());
                 $this->saveLDAPInfo($ldap_info);
                 return id(new AphrontRedirectResponse())->setURI('/settings/page/ldap/');
             }
             if ($ldap_info->getID()) {
                 $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
                 $known_user = id(new PhabricatorUser())->load($ldap_info->getUserID());
                 $session_key = $known_user->establishSession('web');
                 $this->saveLDAPInfo($ldap_info);
                 $request->setCookie('phusr', $known_user->getUsername());
                 $request->setCookie('phsid', $session_key);
                 $uri = new PhutilURI('/login/validate/');
                 $uri->setQueryParams(array('phusr' => $known_user->getUsername()));
                 return id(new AphrontRedirectResponse())->setURI((string) $uri);
             }
             $controller = newv('PhabricatorLDAPRegistrationController', array($this->getRequest()));
             $controller->setLDAPProvider($this->provider);
             $controller->setLDAPInfo($ldap_info);
             return $this->delegateToController($controller);
         }
     }
     $ldap_form = new AphrontFormView();
     $ldap_form->setUser($request->getUser())->setAction('/ldap/login/')->appendChild(id(new AphrontFormTextControl())->setLabel('LDAP username')->setName('username')->setValue($ldap_username))->appendChild(id(new AphrontFormPasswordControl())->setLabel('Password')->setName('password'));
     $ldap_form->appendChild(id(new AphrontFormSubmitControl())->setValue('Login'));
     $panel = new AphrontPanelView();
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild('<h1>LDAP login</h1>');
     $panel->appendChild($ldap_form);
     if (isset($errors) && count($errors) > 0) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Login Failed');
         $error_view->setErrors($errors);
     }
     return $this->buildStandardPageResponse(array(isset($error_view) ? $error_view : null, $panel), array('title' => 'Login'));
 }
开发者ID:nexeck,项目名称:phabricator,代码行数:78,代码来源:PhabricatorLDAPLoginController.php

示例15: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $editable = $this->getAccountEditable();
     // There's no sense in showing a change password panel if the user
     // can't change their password
     if (!$editable || !PhabricatorEnv::getEnvConfig('auth.password-auth-enabled')) {
         return new Aphront400Response();
     }
     $min_len = PhabricatorEnv::getEnvConfig('account.minimum-password-length');
     $min_len = (int) $min_len;
     // NOTE: To change your password, you need to prove you own the account,
     // either by providing the old password or by carrying a token to
     // the workflow from a password reset email.
     $token = $request->getStr('token');
     if ($token) {
         $valid_token = $user->validateEmailToken($token);
     } else {
         $valid_token = false;
     }
     $e_old = true;
     $e_new = true;
     $e_conf = true;
     $errors = array();
     if ($request->isFormPost()) {
         if (!$valid_token) {
             if (!$user->comparePassword($request->getStr('old_pw'))) {
                 $errors[] = 'The old password you entered is incorrect.';
                 $e_old = 'Invalid';
             }
         }
         $pass = $request->getStr('new_pw');
         $conf = $request->getStr('conf_pw');
         if (strlen($pass) < $min_len) {
             $errors[] = 'Your new password is too short.';
             $e_new = 'Too Short';
         }
         if ($pass !== $conf) {
             $errors[] = 'New password and confirmation do not match.';
             $e_conf = 'Invalid';
         }
         if (!$errors) {
             $user->setPassword($pass);
             // This write is unguarded because the CSRF token has already
             // been checked in the call to $request->isFormPost() and
             // the CSRF token depends on the password hash, so when it
             // is changed here the CSRF token check will fail.
             $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
             $user->save();
             unset($unguarded);
             if ($valid_token) {
                 // If this is a password set/reset, kick the user to the home page
                 // after we update their account.
                 $next = '/';
             } else {
                 $next = '/settings/page/password/?saved=true';
             }
             return id(new AphrontRedirectResponse())->setURI($next);
         }
     }
     $notice = null;
     if (!$errors) {
         if ($request->getStr('saved')) {
             $notice = new AphrontErrorView();
             $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
             $notice->setTitle('Changes Saved');
             $notice->appendChild('<p>Your password has been updated.</p>');
         }
     } else {
         $notice = new AphrontErrorView();
         $notice->setTitle('Error Changing Password');
         $notice->setErrors($errors);
     }
     $len_caption = null;
     if ($min_len) {
         $len_caption = 'Minimum password length: ' . $min_len . ' characters.';
     }
     $form = new AphrontFormView();
     $form->setUser($user)->addHiddenInput('token', $token);
     if (!$valid_token) {
         $form->appendChild(id(new AphrontFormPasswordControl())->setLabel('Old Password')->setError($e_old)->setName('old_pw'));
     }
     $form->appendChild(id(new AphrontFormPasswordControl())->setLabel('New Password')->setError($e_new)->setName('new_pw'));
     $form->appendChild(id(new AphrontFormPasswordControl())->setLabel('Confirm Password')->setCaption($len_caption)->setError($e_conf)->setName('conf_pw'));
     $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Save'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Change Password');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild($form);
     return id(new AphrontNullView())->appendChild(array($notice, $panel));
 }
开发者ID:ramons03,项目名称:phabricator,代码行数:92,代码来源:PhabricatorUserPasswordSettingsPanelController.php


注:本文中的AphrontErrorView::setErrors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。