Skip to content

Commit

Permalink
fixed password reset endpoint. It's now available in the open account…
Browse files Browse the repository at this point in the history
… api
  • Loading branch information
aventurella committed Oct 15, 2010
1 parent d1717ef commit 99b87df
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion application/data/YSSCompany.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class YSSCompany
public $domain;
public $timestamp;
public $users;
public $logo;
public $logo = YSSAttachment::attachmentEndpointWithId("domain-logo");

public static $default_logo = "/resources/imgs/peeq-domain-logo.jpg";

Expand Down
38 changes: 38 additions & 0 deletions application/services/accounts-open.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function registerServiceEndpoints($method)
$this->addEndpoint("POST", "/api/account/logout", "logout");
$this->addEndpoint("POST", "/api/account/login", "login");
$this->addEndpoint("POST", "/api/account/register", "registerAccount");
$this->addEndpoint("POST", "/api/account/{domain}/users/reset/{email}", "resetPassword");
}
}

Expand Down Expand Up @@ -257,6 +258,43 @@ public function registerAccount()
echo json_encode($response);
}

public function resetPassword($domain, $email)
{
// always returing {ok:true} here no matter what $email or $domain is given
// no need to let people know what the real domains / accounts are.

$response = new stdClass();
$response->ok = true;

$data = array('domain' => $domain, 'email' => $mail);
$context = array(AMForm::kDataKey=>$data);
$input = AMForm::formWithContext($context);

$input->addValidator(new AMEmailValidator('email', AMValidator::kOptional, 'Invalid email address'));
$input->addValidator(new AMPatternValidator('domain', AMValidator::kRequired, '/^[a-zA-Z0-9-]+$/', "Invalid domain. Expecting minimum 1 character. Cannot contain spaces"));

if($input->isValid)
{
$user = YSSUser::userWithEmailInDomain($email, $domain);

if($user)
{
require YSSApplication::basePath().'/application/mail/YSSMessagePasswordReset.php';

$newPassword = YSSSecurity::generate_password();
$user->password = YSSUser::passwordWithStringAndDomain($newPassword, $domain);
$user->save();

$message = new YSSMessagePasswordReset($user->email);
$message->password = $newPassword;
$message->domain = $domain;
$message->send();
}
}

echo json_encode($response);
}

}

$manager = new AMServiceManager();
Expand Down
38 changes: 0 additions & 38 deletions application/services/accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public function registerServiceEndpoints($method)
break;

case "POST":
$this->addEndpoint("POST", "/api/account/{domain}/users/reset/{email}", "resetPassword");
$this->addEndpoint("POST", "/api/account/{domain}/users/{username}", "updateUserInDomain");
$this->addEndpoint("POST", "/api/account/{domain}/users", "addUserInDomain");
$this->addEndpoint("POST", "/api/account/{domain}", "updateDomain");
Expand Down Expand Up @@ -115,43 +114,6 @@ public function updateDomain($domain)
echo json_encode($response);
}

public function resetPassword($domain, $email)
{
// always returing {ok:true} here no matter what $email or $domain is given
// no need to let people know what the real domains / accounts are.

$response = new stdClass();
$response->ok = true;

$data = array('domain' => $domain, 'email' => $mail);
$context = array(AMForm::kDataKey=>$data);
$input = AMForm::formWithContext($context);

$input->addValidator(new AMEmailValidator('email', AMValidator::kOptional, 'Invalid email address'));
$input->addValidator(new AMPatternValidator('domain', AMValidator::kRequired, '/^[a-zA-Z0-9-]+$/', "Invalid domain. Expecting minimum 1 character. Cannot contain spaces"));

if($input->isValid)
{
$user = YSSUser::userWithEmailInDomain($email, $domain);

if($user)
{
require YSSApplication::basePath().'/application/mail/YSSMessagePasswordReset.php';

$newPassword = YSSSecurity::generate_password();
$user->password = YSSUser::passwordWithStringAndDomain($newPassword, $domain);
$user->save();

$message = new YSSMessagePasswordReset($user->email);
$message->password = $newPassword;
$message->domain = $domain;
$message->send();
}
}

echo json_encode($response);
}

public function deleteUserInDomain($domain, $username)
{
$response = new stdClass();
Expand Down

0 comments on commit 99b87df

Please sign in to comment.