public function testPasswordResetUsingConfirmationCode() { if (!$this->serviceExists('mymail')) { $emailService = \DreamFactory\Core\Models\Service::create(["name" => "mymail", "label" => "Test mail service", "description" => "Test mail service", "is_active" => true, "type" => "local_email", "mutable" => true, "deletable" => true, "config" => ["driver" => "sendmail", "command" => "/usr/sbin/sendmail -bs"]]); $userConfig = \DreamFactory\Core\User\Models\UserConfig::find(4); $userConfig->password_email_service_id = $emailService->id; $userConfig->save(); } if (!\DreamFactory\Core\Models\EmailTemplate::whereName('mytemplate')->exists()) { $template = \DreamFactory\Core\Models\EmailTemplate::create(['name' => 'mytemplate', 'description' => 'test', 'to' => $this->user2['email'], 'subject' => 'rest password test', 'body_text' => 'link {link}']); $userConfig = \DreamFactory\Core\User\Models\UserConfig::find(4); $userConfig->password_email_template_id = $template->id; $userConfig->save(); } Arr::set($this->user2, 'email', '*****@*****.**'); $user = $this->createUser(2); Config::set('mail.pretend', true); $rs = $this->makeRequest(Verbs::POST, static::RESOURCE, ['reset' => 'true'], ['email' => $user['email']]); $content = $rs->getContent(); $this->assertTrue($content['success']); /** @var User $userModel */ $userModel = User::find($user['id']); $code = $userModel->confirm_code; $rs = $this->makeRequest(Verbs::POST, static::RESOURCE, ['login' => 'true'], ['email' => $user['email'], 'code' => $code, 'new_password' => '778877']); $content = $rs->getContent(); $this->assertTrue($content['success']); $this->assertTrue(Session::isAuthenticated()); $userModel = User::find($user['id']); $this->assertEquals('y', $userModel->confirm_code); $this->service = ServiceHandler::getService($this->serviceId); $rs = $this->makeRequest(Verbs::POST, 'session', [], ['email' => $user['email'], 'password' => '778877']); $content = $rs->getContent(); $this->assertTrue(!empty($content['session_id'])); }
protected function getRecordExtras() { $emailService = Service::whereName('email')->first(); $emailTemplateInvite = EmailTemplate::whereName('User Invite Default')->first(); $emailTemplatePassword = EmailTemplate::whereName('Password Reset Default')->first(); $emailTemplateOpenReg = EmailTemplate::whereName('User Registration Default')->first(); return ['config' => ['allow_open_registration' => false, 'open_reg_email_service_id' => !empty($emailService) ? $emailService->id : null, 'open_reg_email_template_id' => !empty($emailTemplateOpenReg) ? $emailTemplateOpenReg->id : null, 'invite_email_service_id' => !empty($emailService) ? $emailService->id : null, 'invite_email_template_id' => !empty($emailTemplateInvite) ? $emailTemplateInvite->id : null, 'password_email_service_id' => !empty($emailService) ? $emailService->id : null, 'password_email_template_id' => !empty($emailTemplatePassword) ? $emailTemplatePassword->id : null]]; }
/** * @param $name * * @throws NotFoundException * * @return array */ public static function getTemplateDataByName($name) { // find template in system db $template = EmailTemplate::whereName($name)->first(); if (empty($template)) { throw new NotFoundException("Email Template '{$name}' not found"); } return $template->toArray(); }