Skip to content

Commit

Permalink
Merge branch 'hotfix/0.18.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mathias-weitz-cross-solutions committed Apr 23, 2015
2 parents 29a531e + 5deed4a commit 64c6731
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 67 deletions.
2 changes: 1 addition & 1 deletion module/Auth/config/module.auth.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ return array(
),
),
'captcha' => array(
'use' => 'image',
'use' => 'reCaptcha', // possible Values are 'image' or 'reCaptcha'
'reCaptcha' => array(
// these information you need to get from: https://www.google.com/recaptcha/admin#list
'public_key' => '%%captcha.recapture.public_key%%', // "site_key"
Expand Down
66 changes: 40 additions & 26 deletions module/Auth/src/Auth/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Auth\Controller;

use Auth\AuthenticationService;
use Auth\Service\Exception;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Log\LoggerInterface;
use Zend\View\Model\ViewModel;
Expand Down Expand Up @@ -38,14 +39,20 @@ class IndexController extends AbstractActionController
*/
protected $logger;

/**
* @var
*/
protected $options;

/**
* @param $auth
* @param $loginForm
*/
public function __construct($auth,$logger,$loginForm) {
public function __construct($auth, $logger, $loginForm, $options) {
$this->auth=$auth;
$this->loginForm=$loginForm;
$this->logger=$logger;
$this->options = $options;
}

/**
Expand Down Expand Up @@ -163,14 +170,12 @@ public function loginAction()
$resultMessage = $result->getMessages();

if (array_key_exists('firstLogin', $resultMessage) && $resultMessage['firstLogin'] === True) {
$this->logger->debug('first login via ' . $provider);

if (array_key_exists('user', $resultMessage)) {
$user=$auth->getUser();

$password = substr(md5(uniqid()),0,6);

$login = uniqid() . ($config['auth']['suffix']!=""?'@'.$config['auth']['suffix']:'');
try {
$user = $auth->getUser();
$password = substr(md5(uniqid()),0,6);
$login = uniqid() . ($this->options->auth_suffix != "" ? '@' . $this->options->auth_suffix : '');
$externalLogin = isset($user->login)?$user->login:'-- not communicated --';
$this->logger->debug('first login via ' . $provider . ' as: ' . $externalLogin);

$scheme = '';
$domain = '';
Expand All @@ -181,33 +186,42 @@ public function loginAction()
}
$viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
$basePath = $viewHelperManager->get('basePath')->__invoke();

$user->login=$login;
$user->setPassword($password);
$user->role=$config['first_login']['role'];
$user->role = $this->options->role;

$mail = $this->mail(
array('displayName'=>$user->info->getDisplayName(),
'provider' => $provider,
'user' => $login,
'password' => $password,
'uri' => $scheme . '://' . $domain . $basePath)
array( 'from' => $this->options->mail_from,
'fromName' => $this->options->mail_name,
'subject' => 'registration at the YAWIK',
'displayName'=> $user->info->getDisplayName(),
'provider' => $provider,
'user' => $login,
'password' => $password,
'uri' => $scheme . '://' . $domain . $basePath)
);
$mail->template('first-login');
$mail->addTo($user->info->getEmail());
$mail->setFrom('[email protected]', $config['first_login']['mail_name']);
$mail->setSubject($config['first_login']['mail_subject']);
$mail->setSubject($this->options->mail_subject);

$loggerId = $login . ' (' . $provider . ': ' . $externalLogin . ')';
if (isset($mail) && $this->mailer($mail)) {
$this->logger->info('Mail first-login for ' . $loggerId . ' sent to ' . $user->info->getEmail());
} else {
$this->logger->warn('No Mail was sent for ' . $loggerId);
}
}
if (isset($mail) && $this->mailer($mail)) {
$this->logger->info('Mail first-login sent to ' . $user->info->getEmail());
} else {
$this->logger->warn('No Mail was sent');
catch (\Exception $e) {
$this->logger->crit($e);
$this->notification()->danger(
/*@translate*/ 'An unexpected error has occurred, please contact your system administrator'
);
}

}

$user = $auth->getUser();
$this->logger->info('User ' . $auth->getUser()->getInfo()->getDisplayName() . ' logged in via ' . $provider);
//$user = $auth->getUser();
//$this->logger->info('User ' . $auth->getUser()->getInfo()->getDisplayName() . ' logged in via ' . $provider);
$settings = $user->getSettings('Core');
if (null !== $settings->localization->language) {
$basePath = $this->getRequest()->getBasePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Log\LoggerInterface;
use Auth\Options\ControllerIndexOptions;
use Auth\Controller\IndexController;

class IndexControllerFactory implements FactoryInterface {
Expand All @@ -31,7 +32,16 @@ public function createService(ServiceLocatorInterface $controllerManager)
$loginForm = $serviceLocator->get('Auth\Form\Login');
/* @var $logger LoggerInterface*/
$logger = $serviceLocator->get('Core/Log');
$controller = new IndexController($auth,$logger,$loginForm);
$config = $serviceLocator->get('config');

$mailOptions = array();
if (array_key_exists('Auth', $config) && array_key_exists('first_login', $config['Auth'])) {
$mailOptions = $config['Auth']['first_login'];
}
$options = new ControllerIndexOptions($mailOptions);


$controller = new IndexController($auth,$logger,$loginForm, $options);
return $controller;
}

Expand Down
14 changes: 13 additions & 1 deletion module/Auth/src/Auth/Listener/MailForgotPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function __invoke(AuthEvent $e)
{
/** @var ServiceManager $serviceManager */
$serviceManager = $this->getServiceManager();
$config = $serviceManager->get('config');

/**
* the sender of the mail is the currently logged in user
Expand All @@ -57,6 +58,17 @@ public function __invoke(AuthEvent $e)
//$controllerPluginManager = $serviceManager->get('controllerPluginManager');
//$urlPlugin = $controllerPluginManager->get('url');

$fromEmail = 'Yawik-System';
$fromName = $userName;
if (array_key_exists('mails', $config) && array_key_exists('from', $config['mails'])) {
if (array_key_exists('email', $config['mails']['from'])) {
$fromEmail = $config['mails']['from']['email'];
}
if (array_key_exists('name', $config['mails']['from'])) {
$fromName = $config['mails']['from']['name'];
}
}

/**
* the receiver of the mail is the "admin" of the running yawik installation
*/
Expand All @@ -68,7 +80,7 @@ public function __invoke(AuthEvent $e)
$mail->setTemplate('mail/forgotPassword');
$mail->setSubject( /*translate*/ 'new Password');
$mail->setTo($userEmail);
$mail->setFrom('Yawik-System', $userName);
$mail->setFrom($fromEmail, $fromName);
$mailService->send($mail);
return;

Expand Down
184 changes: 184 additions & 0 deletions module/Auth/src/Auth/Options/ControllerIndexOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?php
/**
* YAWIK
*
* @filesource
* @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de)
* @license MIT
* @author [email protected]
*/

namespace Auth\Options;

use Zend\Stdlib\AbstractOptions;

/**
* Class ListenerPublisherOptions
* @package YawikXingVendorApi\Options
*/
class ControllerIndexOptions extends AbstractOptions {

/**
* the preview indicates, that a job is not shown
* @var bool
*/
protected $fromEmail = '[email protected]';

/**
* if no organizationId was set, return the id of the Sandbox
* Jobs in the sandbox can not be inspected in the backend, their
* only function is to get a negative or positive answer from the transmit
* @var string
*/
protected $fromName = 'YAWIK';

/**
* @var string
*/
protected $role = 'recruiter';

/**
* @var
*/
protected $mailName = 'Yawik';

/**
* @var
*/
protected $mailFrom = '[email protected]';

/**
* @var
*/
protected $mailSubject = 'Welcome to YAWIK';

/**
* @var
*/
protected $authSuffix = 'yawik';

/**
* @param $role
* @return $this
*/
public function setRole($role)
{
$this->role = $role;
return $this;
}

/**
* @return string
*/
public function getRole()
{
return $this->role;
}

/**
* @param $mailName
* @return $this
*/
public function setMailName($mailName)
{
$this->mailName = $mailName;
return $this;
}

/**
* @return string
*/
public function getMailName()
{
return $this->mailName;
}

/**
* @param $mail
* @return $this
*/
public function setMailFrom($mail)
{
$this->fromEmail = $mail;
return $this;
}

/**
* @return string
*/
public function getMailFrom()
{
return $this->mailFrom;
}

/**
* @param $subject
* @return $this
*/
public function setMailSubject($subject)
{
$this->mailSubject = $subject;
return $this;
}

/**
* @return string
*/
public function getMailSubject()
{
return $this->mailSubject;
}

/**
* @param $suffix
* @return $this
*/
public function setAuthSuffix($suffix)
{
$this->authSuffix = $suffix;
return $this;
}

/**
* @return string
*/
public function getAuthSuffix()
{
return $this->authSuffix;
}

/**
*
*/
public function getEmail()
{
return $this->fromEmail;
}

/**
*
*/
public function setEmail($fromEmail)
{
$this->fromEmail = $fromEmail;
return $this;
}

/**
*
*/
public function getName()
{
return $this->fromName;
}

/**
*
*/
public function setName($fromName)
{
$this->fromName = $fromName;
return $this;
}

}
Loading

0 comments on commit 64c6731

Please sign in to comment.