Plugin Directory

Changeset 2058400


Ignore:
Timestamp:
03/27/2019 03:43:52 PM (7 years ago)
Author:
rleon.uy
Message:

WP-19 Use swagger REST API

WP-22 Configure the URL to which the user will be redirected after logging in

WP-23 Improve style of login form

Location:
cyclos/trunk
Files:
1 added
131 deleted
9 edited
1 moved

Legend:

Unmodified
Added
Removed
  • cyclos/trunk/Cyclos/AccessClientService.php

    r1526725 r2058400  
    22
    33/**
    4  * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html
    5  *
    6  * Generated with Cyclos 4.7
    7  *
    8  * WARNING: The API is subject to change between revision versions
    9  * (for example, 4.5 to 4.6).
     4 * Access clients provide a token for user authentication without decoupled from the login name and password
    105 */
    116class AccessClientService extends Service {
    127
    138    function __construct() {
    14         parent::__construct('accessClientService');
     9        parent::__construct('clients');
    1510    }
    1611   
    1712    /**
    18      * @param activationCode Java type: java.lang.String     * @param prefix Java type: java.lang.String
    19      * @return Java type: org.cyclos.model.access.clients.ActivateAccessClientDTO
    20      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#activate(java.lang.String,%20java.lang.String)
     13     * Activates an access client
    2114     */
    22     public function activate($activationCode, $prefix) {
    23         return $this->run('activate', array($activationCode, $prefix));
    24     }
    25    
    26     /**
    27      * @param params Java type: org.cyclos.model.access.clients.AccessClientActionParams
    28      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#block(org.cyclos.model.access.clients.AccessClientActionParams)
    29      */
    30     public function block($params) {
    31         $this->run('block', array($params));
    32     }
    33    
    34     /**
    35      * @param params Java type: org.cyclos.model.access.clients.AccessClientActionParams
    36      * @return Java type: java.lang.String
    37      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#getActivationCode(org.cyclos.model.access.clients.AccessClientActionParams)
    38      */
    39     public function getActivationCode($params) {
    40         return $this->run('getActivationCode', array($params));
    41     }
    42    
    43     /**
    44      * @param id Java type: java.lang.Long
    45      * @return Java type: D
    46      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#getData(java.lang.Long)
    47      */
    48     public function getData($id) {
    49         return $this->run('getData', array($id));
    50     }
    51    
    52     /**
    53      * @param params Java type: DP
    54      * @return Java type: D
    55      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#getDataForNew(DP)
    56      */
    57     public function getDataForNew($params) {
    58         return $this->run('getDataForNew', array($params));
    59     }
    60    
    61     /**
    62      * @param principalType Java type: org.cyclos.model.access.principaltypes.PrincipalTypeVO     * @param user Java type: org.cyclos.model.users.users.UserLocatorVO
    63      * @return Java type: org.cyclos.model.access.clients.AccessClientsListData
    64      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#getListData(org.cyclos.model.access.principaltypes.PrincipalTypeVO,%20org.cyclos.model.users.users.UserLocatorVO)
    65      */
    66     public function getListData($principalType, $user) {
    67         return $this->run('getListData', array($principalType, $user));
    68     }
    69    
    70     /**
    71 
    72      * @return Java type: org.cyclos.model.access.clients.AccessClientsSearchData
    73      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#getSearchData()
    74      */
    75     public function getSearchData() {
    76         return $this->run('getSearchData', array());
    77     }
    78    
    79     /**
    80      * @param user Java type: org.cyclos.model.users.users.UserLocatorVO     * @param channel Java type: org.cyclos.model.access.channels.ChannelVO
    81      * @return Java type: java.util.List
    82      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#getTypeData(org.cyclos.model.users.users.UserLocatorVO,%20org.cyclos.model.access.channels.ChannelVO)
    83      */
    84     public function getTypeData($user, $channel) {
    85         return $this->run('getTypeData', array($user, $channel));
    86     }
    87    
    88     /**
    89      * @param id Java type: java.lang.Long
    90      * @return Java type: DTO
    91      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#load(java.lang.Long)
    92      */
    93     public function load($id) {
    94         return $this->run('load', array($id));
    95     }
    96    
    97     /**
    98      * @param locator Java type: org.cyclos.model.access.clients.AccessClientLocator
    99      * @return Java type: org.cyclos.model.access.clients.AccessClientVO
    100      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#locate(org.cyclos.model.access.clients.AccessClientLocator)
    101      */
    102     public function locate($locator) {
    103         return $this->run('locate', array($locator));
    104     }
    105    
    106     /**
    107      * @param id Java type: java.lang.Long
    108      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#remove(java.lang.Long)
    109      */
    110     public function remove($id) {
    111         $this->run('remove', array($id));
    112     }
    113    
    114     /**
    115      * @param ids Java type: java.util.Collection
    116      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#removeAll(java.util.Collection)
    117      */
    118     public function removeAll($ids) {
    119         $this->run('removeAll', array($ids));
    120     }
    121    
    122     /**
    123      * @param object Java type: DTO
    124      * @return Java type: java.lang.Long
    125      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#save(DTO)
    126      */
    127     public function save($object) {
    128         return $this->run('save', array($object));
    129     }
    130    
    131     /**
    132      * @param query Java type: org.cyclos.model.access.clients.AccessClientQuery
    133      * @return Java type: org.cyclos.utils.Page
    134      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#search(org.cyclos.model.access.clients.AccessClientQuery)
    135      */
    136     public function search($query) {
    137         return $this->run('search', array($query));
    138     }
    139    
    140     /**
    141      * @param params Java type: org.cyclos.model.access.clients.AccessClientActionParams
    142      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#unassign(org.cyclos.model.access.clients.AccessClientActionParams)
    143      */
    144     public function unassign($params) {
    145         $this->run('unassign', array($params));
    146     }
    147    
    148     /**
    149      * @param action Java type: org.cyclos.model.ActionWithConfirmationPassword
    150      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#unassignCurrent(org.cyclos.model.ActionWithConfirmationPassword)
    151      */
    152     public function unassignCurrent($action) {
    153         $this->run('unassignCurrent', array($action));
    154     }
    155    
    156     /**
    157      * @param params Java type: org.cyclos.model.access.clients.AccessClientActionParams
    158      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/access/AccessClientService.html#unblock(org.cyclos.model.access.clients.AccessClientActionParams)
    159      */
    160     public function unblock($params) {
    161         $this->run('unblock', array($params));
    162     }
     15    public function activate($code, $prefix) {
     16        return $this->post('activate', NULL, array('code'=> $code, 'prefix'=> $prefix));
     17    }     
    16318   
    16419}
  • cyclos/trunk/Cyclos/AuthService.php

    r2049868 r2058400  
    22
    33/**
    4  * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html
    5  *
    6  * Generated with Cyclos 4.7
    7  *
    8  * WARNING: The API is subject to change between revision versions
    9  * (for example, 4.5 to 4.6).
     4 * Operations regarding the user authentication, such as login / logout, activating / deactivating an access client and obtaining the current authenticated user information.
    105 */
    11 class UserService extends Service {
     6class AuthService extends Service {
    127
    138    function __construct() {
    14         parent::__construct('userService');
     9        parent::__construct('auth');
    1510    }
    1611   
    1712    /**
    18      * @param owner Java type: org.cyclos.model.users.users.UserLocatorVO     * @param contact Java type: org.cyclos.model.users.users.UserLocatorVO
    19      * @return Java type: boolean
    20      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#addContact(org.cyclos.model.users.users.UserLocatorVO,%20org.cyclos.model.users.users.UserLocatorVO)
     13     * Returns data about the currently authenticated user
    2114     */
    22     public function addContact($owner, $contact) {
    23         return $this->run('addContact', array($owner, $contact));
     15    public function getCurrentAuth() {
     16        return $this->get();
    2417    }
    2518   
    2619    /**
    27      * @param params Java type: org.cyclos.model.users.users.UserQuery
    28      * @return Java type: org.cyclos.server.utils.SerializableInputStream
    29      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#exportToCSV(org.cyclos.model.users.users.UserQuery)
     20     * Logs-in the currently authenticated user
    3021     */
    31     public function exportToCSV($params) {
    32         return $this->run('exportToCSV', array($params));
     22    public function login() {
     23        return $this->post('session');
    3324    }
    3425   
    3526    /**
    36      * @param locator Java type: org.cyclos.model.users.users.UserLocatorVO
    37      * @return Java type: org.cyclos.model.system.configurations.ActiveConfigurationData
    38      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#getActiveConfiguration(org.cyclos.model.users.users.UserLocatorVO)
     27     * Returns data containing the configuration for logging-in
     28     * Contains data useful for login, such as the allowed user identification methods, the password type and data for the forgot password request.
    3929     */
    40     public function getActiveConfiguration($locator) {
    41         return $this->run('getActiveConfiguration', array($locator));
     30    public function getDataForLogin() {
     31        return $this->get('data-for-login');
    4232    }
    4333   
    4434    /**
    45      * @param id Java type: java.lang.Long
    46      * @return Java type: org.cyclos.model.access.passwords.PasswordInputDTO
    47      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#getConfirmationPasswordInputForRemove(java.lang.Long)
     35     * Requests a forgotten password, notifying the user with instructions to reset it
    4836     */
    49     public function getConfirmationPasswordInputForRemove($id) {
    50         return $this->run('getConfirmationPasswordInputForRemove', array($id));
    51     }
    52    
    53     /**
    54 
    55      * @return Java type: org.cyclos.model.users.users.UserWithRolesVO
    56      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#getCurrentUser()
    57      */
    58     public function getCurrentUser() {
    59         return $this->run('getCurrentUser', array());
    60     }
    61    
    62     /**
    63      * @param id Java type: java.lang.Long
    64      * @return Java type: D
    65      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#getData(java.lang.Long)
    66      */
    67     public function getData($id) {
    68         return $this->run('getData', array($id));
    69     }
    70    
    71     /**
    72      * @param params Java type: DP
    73      * @return Java type: D
    74      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#getDataForNew(DP)
    75      */
    76     public function getDataForNew($params) {
    77         return $this->run('getDataForNew', array($params));
    78     }
    79    
    80     /**
    81      * @param group Java type: org.cyclos.model.users.groups.InitialGroupVO
    82      * @return Java type: org.cyclos.model.users.users.PublicRegistrationData
    83      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#getPublicRegistrationData(org.cyclos.model.users.groups.InitialGroupVO)
    84      */
    85     public function getPublicRegistrationData($group) {
    86         return $this->run('getPublicRegistrationData', array($group));
    87     }
    88    
    89     /**
    90 
    91      * @return Java type: java.util.List
    92      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#getPublicRegistrationGroups()
    93      */
    94     public function getPublicRegistrationGroups() {
    95         return $this->run('getPublicRegistrationGroups', array());
    96     }
    97    
    98     /**
    99      * @param context Java type: org.cyclos.model.users.users.UserSearchContext
    100      * @return Java type: org.cyclos.model.users.users.UserSearchData
    101      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#getSearchData(org.cyclos.model.users.users.UserSearchContext)
    102      */
    103     public function getSearchData($context) {
    104         return $this->run('getSearchData', array($context));
    105     }
    106    
    107     /**
    108 
    109      * @return Java type: java.util.List
    110      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#getUserRegistrationGroups()
    111      */
    112     public function getUserRegistrationGroups() {
    113         return $this->run('getUserRegistrationGroups', array());
    114     }
    115    
    116     /**
    117      * @param locator Java type: org.cyclos.model.users.users.UserLocatorVO
    118      * @return Java type: org.cyclos.model.users.users.ViewProfileData
    119      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#getViewProfileData(org.cyclos.model.users.users.UserLocatorVO)
    120      */
    121     public function getViewProfileData($locator) {
    122         return $this->run('getViewProfileData', array($locator));
    123     }
    124    
    125     /**
    126      * @param id Java type: java.lang.Long
    127      * @return Java type: DTO
    128      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#load(java.lang.Long)
    129      */
    130     public function load($id) {
    131         return $this->run('load', array($id));
    132     }
    133    
    134     /**
    135      * @param locator Java type: org.cyclos.model.users.users.UserLocatorVO
    136      * @return Java type: org.cyclos.model.users.users.UserDetailedVO
    137      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#locate(org.cyclos.model.users.users.UserLocatorVO)
    138      */
    139     public function locate($locator) {
    140         return $this->run('locate', array($locator));
    141     }
    142    
    143     /**
    144      * @param query Java type: org.cyclos.model.users.users.UserQuery
    145      * @return Java type: org.cyclos.server.utils.SerializableInputStream
    146      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#printUsers(org.cyclos.model.users.users.UserQuery)
    147      */
    148     public function printUsers($query) {
    149         return $this->run('printUsers', array($query));
    150     }
    151    
    152     /**
    153      * @param user Java type: org.cyclos.model.users.users.PublicRegistrationDTO
    154      * @return Java type: org.cyclos.model.users.users.UserRegistrationResult
    155      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#publicRegister(org.cyclos.model.users.users.PublicRegistrationDTO)
    156      */
    157     public function publicRegister($user) {
    158         return $this->run('publicRegister', array($user));
    159     }
    160    
    161     /**
    162      * @param user Java type: org.cyclos.model.users.users.UserRegistrationDTO
    163      * @return Java type: org.cyclos.model.users.users.UserRegistrationResult
    164      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#register(org.cyclos.model.users.users.UserRegistrationDTO)
    165      */
    166     public function register($user) {
    167         return $this->run('register', array($user));
    168     }
    169    
    170     /**
    171      * @param id Java type: java.lang.Long
    172      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#remove(java.lang.Long)
    173      */
    174     public function remove($id) {
    175         $this->run('remove', array($id));
    176     }
    177    
    178     /**
    179      * @param ids Java type: java.util.Collection
    180      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#removeAll(java.util.Collection)
    181      */
    182     public function removeAll($ids) {
    183         $this->run('removeAll', array($ids));
    184     }
    185    
    186     /**
    187      * @param ids Java type: java.util.Collection     * @param confirmationPassword Java type: java.lang.String
    188      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#removeAllWithConfirmationPassword(java.util.Collection,%20java.lang.String)
    189      */
    190     public function removeAllWithConfirmationPassword($ids, $confirmationPassword) {
    191         $this->run('removeAllWithConfirmationPassword', array($ids, $confirmationPassword));
    192     }
    193    
    194     /**
    195      * @param owner Java type: org.cyclos.model.users.users.UserLocatorVO     * @param contact Java type: org.cyclos.model.users.users.UserLocatorVO
    196      * @return Java type: boolean
    197      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#removeContact(org.cyclos.model.users.users.UserLocatorVO,%20org.cyclos.model.users.users.UserLocatorVO)
    198      */
    199     public function removeContact($owner, $contact) {
    200         return $this->run('removeContact', array($owner, $contact));
    201     }
    202    
    203     /**
    204      * @param id Java type: java.lang.Long     * @param confirmationPassword Java type: java.lang.String
    205      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#removeWithConfirmationPassword(java.lang.Long,%20java.lang.String)
    206      */
    207     public function removeWithConfirmationPassword($id, $confirmationPassword) {
    208         $this->run('removeWithConfirmationPassword', array($id, $confirmationPassword));
    209     }
    210    
    211     /**
    212      * @param object Java type: DTO
    213      * @return Java type: java.lang.Long
    214      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#save(DTO)
    215      */
    216     public function save($object) {
    217         return $this->run('save', array($object));
    218     }
    219    
    220     /**
    221      * @param object Java type: DTO     * @param confirmationPassword Java type: java.lang.String
    222      * @return Java type: java.lang.Long
    223      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#saveWithConfirmationPassword(DTO,%20java.lang.String)
    224      */
    225     public function saveWithConfirmationPassword($object, $confirmationPassword) {
    226         return $this->run('saveWithConfirmationPassword', array($object, $confirmationPassword));
    227     }
    228    
    229     /**
    230      * @param query Java type: org.cyclos.model.users.users.UserQuery
    231      * @return Java type: org.cyclos.utils.Page
    232      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#search(org.cyclos.model.users.users.UserQuery)
    233      */
    234     public function search($query) {
    235         return $this->run('search', array($query));
    236     }
    237    
    238     /**
    239      * @param type Java type: org.cyclos.model.users.users.UserActivityType
    240      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/users/UserService.html#updateUserActivity(org.cyclos.model.users.users.UserActivityType)
    241      */
    242     public function updateUserActivity($type) {
    243         $this->run('updateUserActivity', array($type));
     37    public function forgottenPasswordRequest($user, $captchaResponse) {
     38        $params = new \stdClass();
     39        $params->user = $user;
     40        $params->captcha = $captchaResponse;
     41        return $this->post('forgotten-password/request', NULL, NULL, $params);
    24442    }
    24543   
  • cyclos/trunk/Cyclos/CaptchaService.php

    r1526725 r2058400  
    22
    33/**
    4  * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/system/CaptchaService.html
    5  *
    6  * Generated with Cyclos 4.7
    7  *
    8  * WARNING: The API is subject to change between revision versions
    9  * (for example, 4.5 to 4.6).
     4 * Generate new captcha challenges, which are required for some operations performed as guest, in order to make it harder for bots to abuse the api.
    105 */
    116class CaptchaService extends Service {
    127
    138    function __construct() {
    14         parent::__construct('captchaService');
     9        parent::__construct('captcha');
    1510    }
    1611   
    1712    /**
     13     * Returns a new captcha challenge
     14     */
     15    public function newCaptcha($group = NULL) {
     16        $id = $this->post(NULL, array('group' => $group));       
     17        return strval($id);
     18    }
    1819
    19      * @return Java type: java.lang.Long
    20      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/system/CaptchaService.html#generate()
    21      */
    22     public function generate() {
    23         return $this->run('generate', array());
    24     }
    25    
    2620    /**
    27      * @param id Java type: java.lang.Long     * @param text Java type: java.lang.String
    28      * @return Java type: boolean
    29      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/system/CaptchaService.html#isValid(java.lang.Long,%20java.lang.String)
    30      */
    31     public function isValid($id, $text) {
    32         return $this->run('isValid', array($id, $text));
    33     }
    34    
    35     /**
    36      * @param id Java type: java.lang.Long     * @param basicGroup Java type: org.cyclos.model.users.groups.BasicGroupVO     * @param dimensions Java type: org.cyclos.model.utils.DimensionsDTO
    37      * @return Java type: org.cyclos.server.utils.SerializableInputStream
    38      * @see http://documentation.cyclos.org/4.7/ws-api-docs/org/cyclos/services/system/CaptchaService.html#readImage(java.lang.Long,%20org.cyclos.model.users.groups.BasicGroupVO,%20org.cyclos.model.utils.DimensionsDTO)
    39      */
    40     public function readImage($id, $basicGroup, $dimensions) {
    41         return $this->run('readImage', array($id, $basicGroup, $dimensions));
     21     * Returns a captcha image content
     22     */
     23    public function getCaptchaContent($id, $group = NULL) {
     24        return $this->get(NULL, $id, array('group' => $group, 'width' => '250'));
    4225    }
    4326   
  • cyclos/trunk/Cyclos/Configuration.php

    r1526725 r2058400  
    66 */
    77class Configuration {
    8     private static $rootUrl;
     8   
     9    private static $rootUrl;
    910    private static $accessType;
     11    private static $lastAccessType;
    1012   
    1113    private static $channel;
     
    1921    private static $accessClientToken;
    2022   
     23    private static $redirectUrl;
     24   
     25    private static $debug = false;
     26   
    2127    /**
    2228     * Sets the Cyclos root url
     
    3238        return Configuration::$rootUrl;
    3339    }
    34    
     40   
     41    /**
     42     * Returns if the plugin is in debug mode
     43     */
     44    public static function isDebug() {
     45        return Configuration::$debug;
     46    }
     47   
     48    /**
     49     * Sets if the plugin is in debug mode, useful for
     50     * debugging CURL requests and other important stuff
     51     */
     52    public static function setDebug($debug) {
     53        Configuration::$debug = $debug;
     54    }
     55   
     56    /**
     57     * Configure the request options to be performed as guest
     58     */
     59   public static function setGuest($guest) {
     60        if($guest) {
     61            Configuration::$lastAccessType = Configuration::$accessType;
     62            Configuration::$accessType = 'GUEST';
     63        } else {
     64            Configuration::$accessType = Configuration::$lastAccessType;
     65        }
     66   }
     67
     68    /**
     69     * Sets the redirect URL after a succesful login.
     70     * If empty it will redirect to root URL
     71     */
     72    public static function setRedirectUrl($redirectUrl) {
     73        Configuration::$redirectUrl = $redirectUrl;
     74    }
     75   
     76    /**
     77     * Returns the redirect URL after a succesful login.
     78     * If empty it will redirect to root URL
     79     */
     80    public static function getRedirectUrl() {
     81        return Configuration::$redirectUrl;
     82    }
     83           
    3584    /**
    3685     * Sets the Cyclos channel
     
    82131     * Returns the full url to access the service with the given url part
    83132     */
    84     public static function url($serviceUrlPart) {
    85         return Configuration::$rootUrl . '/web-rpc/' . $serviceUrlPart;
     133    public static function url($serviceUrlPart, $pathVariables, $queryParameters) {     
     134        $url = Configuration::$rootUrl . '/api/' . $serviceUrlPart;
     135               
     136        // Append path variables
     137        if(!empty($pathVariables)) {   
     138            if(is_array($pathVariables)) {
     139                foreach($pathVariables as $variable) {                 
     140                    if(!empty($variable)) {
     141                        $url .= '/' .$variable;
     142                    }
     143                }
     144            } else {
     145                $url .= '/' .$pathVariables;
     146            }
     147        }
     148       
     149       
     150       
     151        // Append query parameters
     152        if(!empty($queryParameters)) {
     153            $keys = array_keys($queryParameters);
     154            foreach($keys as $key) {
     155                $value = $queryParameters[$key];
     156                if(!empty($value)) {
     157                    if(is_array($value)) { // handle array
     158                        $value = implode(',', $value);
     159                    } elseif(!is_string($value)) { // handle object
     160                        $value = \json_encode($value);
     161                    }
     162                    $url .= strpos($url, '?') !== false ? '&' : '?';
     163                    $url .= urlencode($key) . '=' . urlencode($value);
     164                }
     165            }
     166        }                       
     167       
     168        return $url;
    86169    }
    87170   
     
    89172     * Returns the curl options to execute a call of the given operation, with the given parameters
    90173     */
    91     public static function curlOptions($operation, $params) {
    92         // Set the request operation and parameters
    93         $request = new \stdclass();
    94         $request->operation = $operation;
    95         $request->params = $params;
    96        
     174    public static function curlOptions() {
     175               
    97176        // Set the CURL options
    98177        $opts = array(
    99178                CURLOPT_RETURNTRANSFER => true,
    100179                CURLOPT_HTTPHEADER => array('Content-type: application/json', 'Accept: application/json'),
    101                 CURLOPT_POSTFIELDS => \json_encode($request)
     180                CURLOPT_TIMEOUT => 30
    102181        );
    103182
     
    119198                break;
    120199            case 'ACCESS_CLIENT':
    121                 $opts[CURLOPT_HTTPHEADER][] = 'Authorization: Bearer ' . Configuration::$accessClientToken;
     200                $opts[CURLOPT_HTTPHEADER][] = 'Access-Client-Token: ' . Configuration::$accessClientToken;
    122201                break;
    123202        }
  • cyclos/trunk/Cyclos/Service.php

    r1247549 r2058400  
    99    protected function __construct($urlSuffix) {
    1010        $this->urlSuffix = $urlSuffix;
     11    }       
     12   
     13    /**
     14     * Performs a POST request   
     15     */
     16    protected function post($operation = NULL, $pathVariables = NULL, $queryParameters = NULL, $body = NULL) {     
     17        return $this->run($operation, $pathVariables, $queryParameters, 'POST', $body);
    1118    }
    1219   
    13     protected function run($operation, $params) {
     20    /**
     21     * Performs a GET request
     22     */
     23    protected function get($operation = NULL, $pathVariables = NULL, $queryParameters = NULL, $body = NULL) {
     24        return $this->run($operation, $pathVariables, $queryParameters, 'GET', $body);
     25    }
     26   
     27    /**
     28     * Performs a PUT request
     29     */
     30    protected function put($operation = NULL, $pathVariables = NULL, $queryParameters = NULL, $body = NULL) {
     31        return $this->run($operation, $pathVariables, $queryParameters, 'PUT', $body);
     32    }
     33   
     34    /**
     35     * Performs a DELETE request
     36     */
     37    protected function delete($operation = NULL, $pathVariables = NULL, $queryParameters = NULL, $body = NULL) {
     38        return $this->run($operation, $pathVariables, $queryParameters, 'DELETE', $body);
     39    }
     40   
     41    /**
     42     * Appends with curl the given body as post field   
     43     */
     44    private function postParams(&$curl, $body) {
     45        if ($body != NULL) {
     46            curl_setopt($curl, CURLOPT_POSTFIELDS, \json_encode($body));
     47        }
     48    }       
     49   
     50    /**
     51     * Performs an HTTP request with the given parameters and method (GET, POST, PUT, DELETE)   
     52     */
     53    private function run($operation, $pathVariables, $queryParameters, $method, $body) {
     54
     55        $debug = Configuration::isDebug();
     56       
    1457        // Setup curl
    15         $url = Configuration::url($this->urlSuffix);
    16         $ch = \curl_init($url);
    17         $options = Configuration::curlOptions($operation, $params);
    18         \curl_setopt_array ($ch, $options);
     58        $url = Configuration::url($this->urlSuffix . (empty($operation) ? '' : '/' . $operation) , $pathVariables, $queryParameters);   
     59        $curl = \curl_init($url);
     60       
     61        switch ($method) {
     62            case 'POST':
     63                curl_setopt($curl, CURLOPT_POST, 1);
     64                $this->postParams($curl, $body);
     65                break;
     66            case 'PUT':
     67                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
     68                $this->postParams($curl, $body);
     69                break;
     70            default:
     71                break;
     72        }       
     73        $options = Configuration::curlOptions();           
     74        \curl_setopt_array ($curl, $options);           
     75       
     76        if($debug) {
     77            $verbose = $this->prepareDebug($curl);
     78        }
    1979       
    2080        // Execute the request
    21         $json = \curl_exec($ch);
    22         $code = \curl_getinfo($ch, CURLINFO_HTTP_CODE);
    23         if ($code == 0) {
    24             // The server couldn't be contacted
    25             throw new ConnectionException();
     81        $response = \curl_exec($curl);
     82       
     83        if($debug) {
     84            $this->debugResponse($curl, $response, $verbose);
    2685        }
    27         $result = \json_decode($json);
    28         if ($code == 200) {
    29             return (property_exists($result, "result")) ? $result->result : NULL;
    30         } else {
    31             $error = $result;
    32             if ($error == NULL) {
    33                 $error = new \stdclass();
    34                 $error->errorCode = 'UNKNOWN';
     86       
     87        $code = \curl_getinfo($curl, CURLINFO_HTTP_CODE);       
     88        $contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
     89        if ($code >= 200 && $code < 300) {
     90            if ($code == 204 || $contentType == NULL) {
     91                return NULL;
     92            } elseif ($this->isJson($response)) {
     93                return \json_decode($response);
     94            } else {
     95                return $response;
    3596            }
    36             throw new ServiceException($this->urlSuffix, $operation, $error->errorCode, $error);
    3797        }
     98       
     99        $error = $response;
     100        if ($error == NULL) {
     101            $error = new \stdclass();
     102            $error->code = 'UNKNOWN';
     103        } elseif ($this->isJson($response)) {
     104            $error = \json_decode($response);
     105        }
     106        throw new ServiceException($this->urlSuffix, $operation, $code, $error);       
     107    }
     108   
     109    /**
     110     * Prepares CURL for debug
     111     */
     112    private function prepareDebug($curl) {
     113        \curl_setopt($curl, CURLOPT_VERBOSE, true);
     114        $verbose = fopen('php://temp', 'w+');
     115        \curl_setopt($curl, CURLOPT_STDERR, $verbose);
     116        return $verbose;
     117    }
     118   
     119    /**
     120     * Prints detailed CURL response
     121     */
     122    private function debugResponse($curl, $response, $verbose) {
     123        $url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
     124       
     125        if ($response === FALSE) {
     126            printf("cUrl error (#%d): %s<br>\n", \curl_errno($curl),
     127            htmlspecialchars(\curl_error($curl)));
     128        }
     129       
     130        rewind($verbose);
     131        $verboseLog = stream_get_contents($verbose);
     132       
     133        echo "  Service URL:\n<pre>" . $url ."</pre>\n     
     134                Request information:\n<pre>", htmlspecialchars($verboseLog), "</pre>\n
     135                Response:\n<pre>". $response ."</pre>";
     136       
     137    }
     138   
     139    /**
     140     * Returns if the given string is a valid JSON
     141     */
     142    private function isJson($string) {
     143        json_decode($string);
     144        return (json_last_error() == JSON_ERROR_NONE);
    38145    }
    39146}
  • cyclos/trunk/Cyclos/ServiceException.php

    r1111214 r2058400  
    33/**
    44 * Exception thrown when there is some error in a cyclos service call.
    5  * Normally, clients should handle the $errorCode property, for strings like PERMISSION_DENIED or INSUFFICIENT_BALANCE.
     5 * Normally, clients should handle the statusCode property to determine the error type
     6 * e.g internal server error (500), not found error (404), etc.
    67 * The $error property contains additional error details.
    78 */
     
    910    public $service;
    1011    public $operation;
    11     public $errorCode;
     12    public $statusCode;
    1213    public $error;
    1314
    14     public function __construct($service, $operation, $errorCode, $error) {
    15         parent::__construct("Error calling Cyclos service: ${service}.${operation}: $errorCode");
     15    public function __construct($service, $operation, $statusCode, $error) {
     16        parent::__construct("Error calling Cyclos service: ${service}.${operation}: $statusCode");
    1617        $this->service = $service;
    1718        $this->operation = $operation;
    18         $this->errorCode = $errorCode;
     19        $this->statusCode = $statusCode;
    1920        $this->error = $error;
    2021    }
  • cyclos/trunk/cyclos-admin.php

    r1809299 r2058400  
    2525/*#################### Creates admin settings page ####################*/
    2626add_action('admin_menu', 'cyclosAdminMenu');
     27
    2728function cyclosAdminMenu() {
    2829    add_options_page('Cyclos', 'Cyclos','manage_options', 'Cyclos', 'cyclosAdminSettingsPage');
     
    7273    if (!empty($rootUrl) && !empty($token)) {
    7374        configureCyclos();
    74         $userService = new Cyclos\UserService();
     75        $authService = new Cyclos\AuthService();
    7576       
    7677        // Get the logged user
    7778        try {
    78             $user = $userService->getCurrentUser();
    79         } catch (Cyclos\ConnectionException $e) {
    80             $errorMessage = $t->errorConnection;
    81         } catch (Cyclos\ServiceException $e) {
    82             $errorMessage = "The current Cyclos plugin settings are not correct.<br>Make sure the administrator user and access client used in Cyclos are active.";
     79            $auth = $authService->getCurrentAuth();
     80        } catch (\Exception $e) {
     81            $errorMessage = handleError($e);
    8382        }
    8483    } else {
     
    8786     
    8887     if (empty($errorMessage)) {
    89         $shortDisplay = $user->shortDisplay ? $user->shortDisplay : $user->username; ?>
     88        $shortDisplay = !empty($auth->user->shortDisplay) ? $auth->user->shortDisplay : $auth->user->display; ?>
    9089        <p>Congratulations! Cyclos is correctly configured for: <a href="<?= $rootUrl ?>"><?= $rootUrl ?></a>.<br>
    9190        The administrator used for access is <b><?= $shortDisplay ?></b>.</p>
     
    117116    $adminuser = get_option('cyclos_adminuser');
    118117    $token = get_option('cyclos_token');
     118    $redirectUrl = get_option('cyclos_redirectUrl');
    119119?>
    120120<div class="wrap">
     
    128128                <td>&nbsp;<input type="text" name="cyclos_url" value="<?= $url ?>" size="50"></td>
    129129                <td>&nbsp; <i>e.g. https://demo.cyclos.org</i></td></tr>
     130            <tr>
     131                <td>Redirect URL:</td>
     132                <td>&nbsp;<input type="text" name="redirect_url" value="<?= $redirectUrl ?>" size="50"></td>
     133                <td>&nbsp; <i>e.g. https://myfrontendsite.com</i></td></tr>
    130134            <tr>
    131135                <td>Cyclos admin username:</td>
     
    203207    // first retreive the posted data
    204208    $url = esc_url($_POST['cyclos_url']);
     209    $redirectUrl = esc_url($_POST['redirect_url']);
    205210    $adminuser = sanitize_text_field($_POST['cyclos_adminuser']);
    206211    // Don't sanitize the password, as it can contain any characters and is sent directly via WS
     
    213218    Cyclos\Configuration::setRootUrl($url);
    214219    Cyclos\Configuration::setAuthentication($adminuser, $adminpwd);
     220    Cyclos\Configuration::setRedirectUrl($redirectUrl);
    215221   
    216222    // Activate the access client
     
    220226        $result = $accessClientService->activate($actcode, null);
    221227        $token = $result->token;
    222     } catch (Cyclos\ConnectionException $e) {
    223         $t = cyclosGetTranslations();
    224         $errorMessage = $t->errorConnection;
    225     } catch (Cyclos\ServiceException $e) {
    226         $t = cyclosGetTranslations();
    227         switch ($e->errorCode) {
    228             case 'CREDENTIALS_NOT_SUPPLIED':
    229                 $errorMessage = "Please, supply both login name and password";
    230                 break;
    231             case 'LOGIN':
    232                 $errorMessage = $t->errorLogin;
    233                 break;
    234             case 'REMOTE_ADDRESS_BLOCKED':
    235                 $errorMessage = "The wordpress IP address has been temporarily blocked by exceeding login attempts";
    236                 break;
    237             case 'ENTITY_NOT_FOUND':
    238                 $errorMessage = "The given activation code didn't match an access client pending activation";
    239                 break;
    240             case 'VALIDATION':
    241                 $errorMessage = validationExceptionMessage($e);
    242                 break;
    243             default:
    244                 $errorMessage = str_replace($t->errorGeneral, "{code}", $e->errorCode);
    245         }
     228    } catch(\Exception $e) {
     229        $errorMessage = handleError($e);
    246230    }
    247231   
     
    249233        // Save the options
    250234        update_option('cyclos_url', $url);
     235        update_option('cyclos_redirectUrl', $redirectUrl);
    251236        update_option('cyclos_adminuser', $adminuser);
    252237        update_option('cyclos_token', $token);
  • cyclos/trunk/cyclos-common.php

    r1248389 r2058400  
    2323defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
    2424
    25 // Class to hold info about a translation key
     25/**
     26 * Class to hold info about a translation key
     27 */
    2628class CyclosKey {
    2729    public function __construct($key, $title, $defaultValue) {
     
    3739   
    3840    public static function getAll() {
    39         $result = new stdclass();
    40         CyclosKey::add($result, "loginTitle", "Login form title", "Member login:");
    41         CyclosKey::add($result, "loginName", "Login name placeholder", "User");
    42         CyclosKey::add($result, "loginPassword", "Password placeholder", "Password");
    43         CyclosKey::add($result, "loginSubmit", "Login button text", "Login");
    44         CyclosKey::add($result, "forgotLink", "Forgot password link", "Forgot your password?");
    45         CyclosKey::add($result, "forgotTitle", "Forgot password title", "Password recovery");
    46         CyclosKey::add($result, "forgotEmail", "E-mail placeholde", "E-mail");
    47         CyclosKey::add($result, "forgotCaptcha", "Captcha placeholder", "Visual validation");
    48         CyclosKey::add($result, "forgotNewCaptcha", "New captcha link", "New code");
    49         CyclosKey::add($result, "forgotCancel", "Cancel forgot password request", "Cancel");
    50         CyclosKey::add($result, "forgotSubmit", "Submit forgot password request", "Submit");
    51         CyclosKey::add($result, "forgotDone", "Forgot password done", "A link to reset your password has been submitted to {email}");
    52         CyclosKey::add($result, "errorLogin", "Error message: invalid login", "Invalid username / password");
    53         CyclosKey::add($result, "errorAddressBlocked", "Error message: address blocked", "Your access is blocked by exceeding invalid login attempts");
    54         CyclosKey::add($result, "errorEmailNotFound", "Error message: invalid e-mail", "The given e-mail address didn't match any valid user");
    55         CyclosKey::add($result, "errorConnection", "Error message: the Cyclos server couldn't be contacted", "The Cyclos server couldn't be contacted");
    56         CyclosKey::add($result, "errorGeneral", "Error message: unknown error", "Error performing the request: {code}");
     41        $result = new stdclass();       
     42        CyclosKey::add($result, 'loginName', 'Login name placeholder', 'User');
     43        CyclosKey::add($result, 'loginPassword', 'Password placeholder', 'Password');
     44        CyclosKey::add($result, 'loginSubmit', 'Login button text', 'Login');
     45        CyclosKey::add($result, 'forgotLink', 'Forgot password link', 'Forgot your password?');       
     46        CyclosKey::add($result, 'forgotEmail', 'Forgot password user placeholder', 'User');
     47        CyclosKey::add($result, 'forgotCaptcha', 'Captcha placeholder', 'Visual validation');
     48        CyclosKey::add($result, 'forgotNewCaptcha', 'New captcha link', 'New code');
     49        CyclosKey::add($result, 'forgotCancel', 'Cancel forgot password request', 'Cancel');
     50        CyclosKey::add($result, 'forgotSubmit', 'Submit forgot password request', 'Submit');
     51        CyclosKey::add($result, 'forgotDone', 'Forgot password done', 'A link to reset your password has been submitted to {email}');
     52             
     53        // Errors       
     54        CyclosKey::add($result, 'errorConnection', 'Error message: the Cyclos server could not be contacted', 'The Cyclos server could not be contacted');       
     55        CyclosKey::add($result, 'errorGeneral', 'Error message: unknown error', 'Error performing the request: {code}');
     56        CyclosKey::add($result, 'errorInaccessibleChannel', 'Error message: inaccessible channel', 'Access denied. The channel used to connect to the server is not allowed or misconfigured');
     57        CyclosKey::add($result, 'errorInaccessiblePrincipal', 'Error message: inaccessible principal', 'You cannot use your {principal} in this channel');
     58        CyclosKey::add($result, 'errorIndefinitelyBlocked', 'Error message: password indefinitely blocked', 'Your password has been disabled by exceeding the maximum of tries.\nPlease, contact the administration');
     59        CyclosKey::add($result, 'errorTemporarilyBlocked', 'Error message: password temporarily blocked', 'Your password has been blocked by exceeding the maximum of tries');
     60        CyclosKey::add($result, "errorLogin", 'Error message: invalid login', 'Invalid username / password');
     61        CyclosKey::add($result, 'errorInvalidPassword', 'Error message: password invalid', 'The given user / password are incorrect. Please, try again');
     62        CyclosKey::add($result, "errorInvalidAccessClient", "Error message: invalid access client", "The current access client is not correctly configured");
     63        CyclosKey::add($result, 'errorOperatorWithPendingAgreements', 'Error message: operator pending agreements', 'A required agreement needs to be accepted by your manager before you can login');       
     64        CyclosKey::add($result, 'errorEntityNotFound', 'Error message: information not found', 'The required information was not found');
     65        CyclosKey::add($result, 'errorEntityNotFoundUser', 'Error message: user not found', 'The user was not found');
     66        CyclosKey::add($result, 'errorEntityNotFoundAccessClient', 'Error message: access client not found', 'The access client was not found or the activation code is not valid');
     67     
    5768        return $result;
    5869    }
    5970}
    6071
    61 // Returns the translated values
     72/**
     73 * Returns the translated values
     74 */
    6275function cyclosGetTranslations() {
    6376    $t = new stdclass();
     
    7285}
    7386
    74 // Function that autoloads Cyclos classes
     87/**
     88 * Autoloads Cyclos classes
     89 */
    7590function autoload_cyclos($c) {
    7691    if (strpos($c, "Cyclos\\") >= 0) {
     
    7994}
    8095
    81 // Sets up the Cyclos services to use the given access token, or load the stored settings if nothing is passed in
     96/**
     97 * Sets up the Cyclos services to use the given access token, or load the stored settings if nothing is passed in
     98 */
    8299function configureCyclos($rootUrl = NULL, $token = NULL) {
    83100    if (empty($rootUrl)) $rootUrl = get_option('cyclos_url');
     
    86103    spl_autoload_register('autoload_cyclos');
    87104    Cyclos\Configuration::setRootUrl($rootUrl);
    88     Cyclos\Configuration::setAccessClientToken($token);
    89 }
    90 
    91 
    92 // Function which returns an appropriate error message for a validation exception
     105    Cyclos\Configuration::setAccessClientToken($token);   
     106    Cyclos\Configuration::setRedirectUrl(get_option('cyclos_redirectUrl'));
     107}
     108
     109/**
     110 * Returns an appropriate error message for a validation exception
     111 */
    93112function validationExceptionMessage($e) {
    94     $val = $e->error->validation;
     113    $val = $e->error;
    95114    $errors = array();
    96115    if (!empty($val->generalErrors)) {
     
    103122    }
    104123    if (empty($errors)) {
    105         return "Validation error";
     124        return 'Validation error';
    106125    } else {
    107         return implode("\n", $errors);
    108     }
     126        return implode('\n', $errors);
     127    }
     128}
     129
     130/**
     131 * Handles the given exception and returns an error message
     132 */
     133function handleError($e) {
     134       
     135    $class = get_class($e);
     136    $t = cyclosGetTranslations();
     137   
     138    $property = NULL;
     139    $errorMessage = NULL;
     140   
     141    if ($class == 'Cyclos\ServiceException') { 
     142        $status = $e->statusCode;       
     143        if($status == 0 || $status == 1 || $status == 503) {
     144            // Connection error
     145            $property = 'errorConnection';
     146        } elseif ($status == 422) {
     147            // Unprocessable entity error
     148            if(property_path_exists($e, 'error->code') && $e->error->code == 'validation') {
     149                $errorMessage = validationExceptionMessage($e);
     150            }
     151        } elseif ($status == 404) {
     152            if(property_path_exists($e, 'error->entityType')) {
     153                // Not found error
     154                $path = 'errorEntityNotFound'.ucwords($e->error->entityType);
     155                $property = property_exists($t, $path) ? $path : 'errorEntityNotFound';             
     156            } else {
     157                // Likely a connection error (no REST API found)
     158                $property = 'errorConnection';
     159            }                   
     160        } elseif (property_path_exists($e, 'error->code')) {       
     161            // Conflict, forbidden or other errors which contains a 'code' attribute           
     162            $property = 'error'.ucwords($e->error->code);           
     163        }
     164    }
     165   
     166    // Show a generic error if there is not a translated message
     167    if(empty($property) || !property_exists($t, $property)) {       
     168        $property = 'errorGeneral';                     
     169    }   
     170
     171    // Replace message parameters
     172    if(empty($errorMessage) && !empty($property)) {
     173       
     174        $errorMessage = $t->{$property};
     175       
     176        switch($property) {
     177            case 'errorGeneral':
     178                $errorMessage = str_replace('{code}', $status, $errorMessage);             
     179                break;
     180            case 'errorInaccessiblePrincipal':
     181                // TODO NO API YET
     182                //$errorMessage = str_replace('{principal}', $e->code, $errorMessage);
     183                break;
     184        }
     185    }
     186               
     187    return $errorMessage;
     188}
     189
     190/**
     191 * Extension of property_exists() function. Searches
     192 * if the he given path exists in the given object
     193 */
     194function property_path_exists($object, $property_path) {
     195   
     196    if(empty($object)) {
     197        return false;
     198    }
     199   
     200    $path_components = explode('->', $property_path);
     201
     202    if (count($path_components) == 1) {
     203        return property_exists($object, $property_path);
     204    } else {
     205        return (
     206            property_exists($object, $path_components[0]) &&
     207            property_path_exists(
     208                $object->{array_shift($path_components)},
     209                    implode('->', $path_components)
     210                        )
     211                );
     212    }
    109213}
    110214
  • cyclos/trunk/cyclos-public.php

    r1951036 r2058400  
    2323defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
    2424
     25// Register style sheet
     26add_action('wp_print_styles', 'registerCyclosStyles', 99);
     27add_action('wp_enqueue_scripts', 'registerJQuery');
     28
    2529/*#################### Creates shortcode and inserts login form ####################*/
    2630add_shortcode( 'cycloslogin', 'cyclosLoginForm' );
    2731
    28 // Register style sheet
    29 add_action( 'wp_enqueue_scripts', 'registerCyclosStyles' );
    30 
    3132// Create the widget to display the login form
    3233add_action('widgets_init',  function(){return register_widget("CyclosPlugin");});
     34
    3335class CyclosPlugin extends WP_Widget {
    3436
     
    4547
    4648function registerCyclosStyles() {
    47     wp_register_style( 'cyclosWordpressStylesheet', plugin_dir_url( __FILE__) . 'stylesheet.css');
    48     wp_enqueue_style( 'cyclosWordpressStylesheet' );
     49    wp_register_style('cyclosWordpressStylesheet', plugin_dir_url( __FILE__) . 'stylesheet.css');
     50    wp_enqueue_style('cyclosWordpressStylesheet' );
     51    wp_enqueue_style('google-fonts','//fonts.googleapis.com/css?family=Open+Sans', array(), NULL);
    4952}   
     53
     54function registerJQuery() {
     55    wp_enqueue_script('jquery');
     56}
    5057
    5158// Function that is called when the shortcode is used
    5259function cyclosLoginForm($atts) {
    5360    configureCyclos();
    54     $loginService = new Cyclos\LoginService();
     61    $authService = new Cyclos\AuthService();
    5562
    5663    $out = '';
    57 
     64    $returnToValue = '';
     65
     66    // Execute this request as guest, otherwise it would return 204 (no content)
     67    Cyclos\Configuration::setGuest(true);
     68    // Request login data for main channel
     69    Cyclos\Configuration::setChannel('main');
     70   
    5871    // See if the forgot password should be shown
    5972    try {
    60         $loginData = $loginService->getLoginData('main');
    61         $showForgotPassword = $loginData->showForgotPassword;
    62     } catch (Exception $e) {
     73        $loginData = $authService->getDataForLogin();         
     74        $showForgotPassword = !empty($loginData) &&
     75                                !empty($loginData->forgotPasswordMediums) &&
     76                                in_array('email', $loginData->forgotPasswordMediums, TRUE);
     77    } catch (Exception $e) {       
    6378        $showForgotPassword = true;
    6479    }
     80   
     81    // Revert guest request and headers
     82    Cyclos\Configuration::setGuest(false);
     83    Cyclos\Configuration::setChannel(NULL);
    6584
    6685    $t = cyclosGetTranslations();
     
    6988
    7089    if ($showForgotPassword) {
    71         $returnToValue = "";
    7290        if(isset($_GET["returnTo"])){
    7391            $returnToValue = $_GET["returnTo"];
     
    7593        $out = $out . '
    7694            <div class="cyclosFormBox cyclosForgotContainer" style="display:none">
    77                 <form class="cyclosForgotPasswordForm" action="#" method="post">
    78                     <div class="cyclosFormTitle">' . $t->forgotTitle . '</div>
     95                <form class="cyclosForgotPasswordForm" action="#" method="post">                   
    7996                    <div class="cyclosFormField">
    80                         <input placeholder="' . $t->forgotEmail . '" name="cyclosEmail" type="email" required>
     97                        <input placeholder="' . $t->forgotEmail . '" name="cyclosEmail" type="text" required>
    8198                    </div>
    8299                    <div class="cyclosFormField">
     
    101118    $out = $out . '
    102119        <div class="cyclosFormBox cyclosLoginContainer">
    103             <form class="cyclosLoginForm" action="#" method="post">
    104                 <div class="cyclosFormTitle">' . $t->loginTitle . '</div>
     120            <form class="cyclosLoginForm" action="#" method="post">               
    105121                <div>
    106122                    <input name="cyclosReturn" value="'. $returnToValue .'" type="hidden">
     
    151167                            $.post("' . admin_url('admin-ajax.php?action=cyclos_login') . '", data)
    152168                                .done(function(response) {
    153                                     response = response || {};
     169                                    response = response || {};                                 
    154170                                    if (response.redirectUrl) {
    155                                         var redirect = response.redirectUrl;
    156                                         if(response.returnTo && response.returnTo !== ""){
    157                                             redirect += "&returnTo=" + encodeURIComponent(response.returnTo);
    158                                         }
    159                                         location.href = redirect;
     171                                        location.href = response.redirectUrl;                                       
    160172                                    } else {
    161173                                        alert(response.errorMessage || "Invalid data received from server");
     
    242254                                        alert(response.errorMessage || "Invalid data received from server");
    243255                                    } else {
     256                                        captchaId = null;
    244257                                        showLogin();
    245258                                        alert("' . $t->forgotDone . '".replace("{email}", email));
     
    280293function cyclosLogin() {
    281294    configureCyclos();
    282     $loginService = new Cyclos\LoginService();
     295    $sessionsService = new Cyclos\SessionsService();
    283296   
    284297    $t = cyclosGetTranslations();
     
    287300    $errorMessage = NULL;
    288301   
     302    $returnTo = $_POST['returnTo'];       
     303
    289304    // Perform the login
    290     try {
    291         $params = new stdclass();
    292         $params->user = array("principal" => sanitize_text_field($_POST["principal"]));
    293         $params->password = sanitize_text_field($_POST["password"]);
    294         $returnTo = $_POST["returnTo"];
    295         $params->remoteAddress = $_SERVER['REMOTE_ADDR'];
    296         $result = $loginService->loginUser($params);
    297     } catch (Cyclos\ConnectionException $e) {
    298         $errorMessage = $t->errorConnection;
    299     } catch (Cyclos\ServiceException $e) {
    300         switch ($e->errorCode) {
    301             case 'VALIDATION':
    302                 $errorMessage = validationExceptionMessage($e);
    303                 break;
    304             case 'LOGIN':
    305             case 'ENTITY_NOT_FOUND':
    306                 $errorMessage = $t->errorLogin;
    307                 break;
    308             case 'REMOTE_ADDRESS_BLOCKED':
    309                 $errorMessage = $t->errorAddressBlocked;
    310                 break;
    311             default:
    312                 $errorMessage = str_replace($t->errorGeneral, "{code}", $e->errorCode);
    313                 break;
    314         }
     305    try {       
     306        $result = $sessionsService->loginUser(
     307                    sanitize_text_field($_POST['principal']),
     308                    sanitize_text_field($_POST['password']),
     309                    $_SERVER['REMOTE_ADDR']);       
     310    } catch (\Exception $e) {       
     311        $errorMessage = handleError($e);
    315312    }
    316313    // Get the redirect url if there were no errors
    317314    if (!empty($result)) {
    318         $redirectUrl = Cyclos\Configuration::getRootUrl() . "?sessionToken=" . $result->sessionToken;
     315        // Check if there is a redirect URL defined otherwise go to classic frontend
     316        $redirectUrl = Cyclos\Configuration::getRedirectUrl();     
     317        if(empty($redirectUrl)) {
     318            $redirectUrl = Cyclos\Configuration::getRootUrl();         
     319        }       
     320   
     321        // Replace with the relative path of the external site (may apply when the
     322        // session expires so we can redirect the user to the last visited page)               
     323        if(strpos($redirectUrl, '%p') !== false) {             
     324            // Append path at the specified position
     325            $redirectUrl = str_replace('%p', (empty($returnTo) ? '/' : $returnTo), $redirectUrl);
     326        } else {               
     327            // Append path at the end
     328            $separator = strripos($redirectUrl, '/') !== false ? '' : '/';
     329            $redirectUrl .= $separator . (empty($returnTo) ? '' : $returnTo);                       
     330        }       
     331        // Replace with session token
     332        if(strpos($redirectUrl, '%s') !== false) {
     333            // Append session token at the specified position
     334            $redirectUrl = str_replace('%s', $result->sessionToken, $redirectUrl);
     335        } else {
     336            // Append session token at the end         
     337            $separator = strripos($redirectUrl, '?') !== false ? '&' : '?';
     338            $redirectUrl .= $separator . 'sessionToken='.$result->sessionToken;         
     339        }
    319340    }
    320341
    321342    // Send the JSON response
    322343    $response = array(
    323         "redirectUrl" => $redirectUrl,
    324         "returnTo" => $returnTo,
    325         "errorMessage" => $errorMessage
     344        'redirectUrl' => $redirectUrl,       
     345        'errorMessage' => $errorMessage
    326346    );
    327347    wp_send_json($response);
     
    343363    // Generate a captcha
    344364    try {
    345         $id = $captchaService->generate();
    346         $content = $captchaService->readImage($id, null, null);
    347     } catch (Cyclos\ConnectionException $e) {
    348         $errorMessage = $t->errorConnection;
    349     } catch (Cyclos\ServiceException $e) {
    350         $errorMessage = str_replace($t->errorGeneral, "{code}", $e->errorCode);
     365        $id = $captchaService->newCaptcha();
     366        $content = base64_encode($captchaService->getCaptchaContent($id));
     367    } catch (\Exception $e) {
     368        $errorMessage = handleError($e);
    351369    }
    352370   
     
    364382add_action( 'wp_ajax_nopriv_cyclos_forgot_password', 'forgotPassword' );
    365383function forgotPassword() {
     384   
    366385    configureCyclos();
    367     $passwordService = new Cyclos\PasswordService();
     386    $authService = new Cyclos\AuthService();
    368387
    369388    $t = cyclosGetTranslations();
     
    371390    // Send the request
    372391    $errorMessage = NULL;
     392       
    373393    try {
    374         $params = new stdclass();
    375         $params->email = sanitize_text_field($_POST["email"]);
    376         $params->captchaId = sanitize_text_field($_POST["captchaId"]);
    377         $params->captchaText = sanitize_text_field($_POST["captchaText"]);
    378         $passwordService->forgotPasswordRequest($params);
    379     } catch (Cyclos\ConnectionException $e) {
    380         $errorMessage = $t->errorConnection;
    381     } catch (Cyclos\ServiceException $e) {
    382         switch ($e->errorCode) {
    383             case 'ENTITY_NOT_FOUND':
    384                 $errorMessage = $t->errorEmailNotFound;
    385                 break;
    386             case 'VALIDATION':
    387                 $errorMessage = validationExceptionMessage($e);
    388                 break;
    389             default:
    390                 $errorMessage = str_replace($t->errorGeneral, "{code}", $e->errorCode);
    391                 break;
    392         }
     394        $captchaResponse = new stdclass();       
     395        $captchaResponse->challenge = sanitize_text_field($_POST["captchaId"]);
     396        $captchaResponse->response = sanitize_text_field($_POST["captchaText"]);       
     397        $authService->forgottenPasswordRequest(
     398                sanitize_text_field($_POST["email"]),
     399                $captchaResponse);
     400    } catch (\Exception $e) {       
     401        $errorMessage = handleError($e);
    393402    }
    394403   
  • cyclos/trunk/stylesheet.css

    r1242511 r2058400  
    1 .cyclosLoginContainer .cyclosFormTitle {
    2     background: url("login.png") no-repeat 0px 0px;
    3 }
    4 
    5 .cyclosForgotContainer .cyclosFormTitle {
    6     background: url("password_recover.png") no-repeat 0px 0px;
     1.cyclosFormBox {
     2    text-align: center;
    73}
    84
    95.cyclosFormBox  form {
    10     width: 200px;
    11     padding: 20px 20px 20px 20px;
    12     border: 1px solid #CCCCCC;
    13     background-color: #F4F5F9;
    14     margin-top:20px;
    15     border-radius: 3px;
    16     box-shadow: inset 1px 1px 1px 0px #FFFFFF;
     6    width: 250px;   
     7    display: inline-block;                 
    178}
    189
    19 .cyclosFormBox  input {
     10.cyclosFormBox input {
    2011    width: 100%;
    21     margin-top: 10px;
    22     font-size: 14px;
    23     padding: 4px 0px;
     12    height: 38px;
     13    margin: 10px 0;
     14    font: normal 13px / 24px "Open Sans", Helvetica, Arial, Verdana, sans-serif;
     15    font-size: 13px;
     16    line-height: 24px;
     17    color: #5f5f5f;
     18    background-color: #f2f2f2;
     19    border: 1px solid #e1e1e1;
     20    box-sizing: border-box;
     21    padding: 7px 15px;
     22    border-radius: 1px;
    2423}
    2524
    26 .cyclosFormBox  .cyclosFormTitle {
    27     font-weight: bold;
    28     margin: 10px 0px 4px 0px;
    29     padding: 0px 0px 0px 20px;
     25.cyclosFormBox input::-webkit-input-placeholder {
     26    color: rgba(139,141,148,0.5);
     27}
     28
     29.cyclosFormBox input:focus,
     30.cyclosFormBox a:focus {
     31    outline: none;
     32    outline-offset: 0;
     33    border-color: #e1e1e1;
    3034}
    3135
     
    3539
    3640.cyclosFormBox  a {
    37     display: block;
    38     text-align: center;
    39     padding: 5px 0px 5px 0px;
    40     font-weight: normal;
    41     font-style: italic;
    42     font-size: 12px;
     41    font-size: 16px;
     42    font-family: "Open sans",Helvetica,Arial,Verdana,sans-serif;
     43    color: #169ad4;
     44    font-style: normal;
     45    font-weight: normal;
     46    text-align: center;
     47    border-bottom: 1px dotted;
     48    text-decoration: none !important;
     49    display: inline;   
     50    padding: 5px 0;
     51}
     52
     53.cyclosFormBox a:hover {
     54    color: #9cb7c3;
     55}
     56
     57.cyclosForgotCancel,
     58.cyclosNewCaptcha {
     59    float: right;
    4360}
    4461
    4562.cyclosFormBox  input[type=button], .cyclosFormBox  input[type=submit] {
    46     background: #84b3df; /* Old browsers */
    47     background: -moz-linear-gradient(top,  #84b3df 0%, #609dd6 100%); /* FF3.6+ */
    48     background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#84b3df), color-stop(100%,#609dd6)); /* Chrome,Safari4+ */
    49     background: -webkit-linear-gradient(top,  #84b3df 0%,#609dd6 100%); /* Chrome10+,Safari5.1+ */
    50     background: -o-linear-gradient(top,  #84b3df 0%,#609dd6 100%); /* Opera 11.10+ */
    51     background: -ms-linear-gradient(top,  #84b3df 0%,#609dd6 100%); /* IE10+ */
    52     background: linear-gradient(to bottom,  #84b3df 0%,#609dd6 100%); /* W3C */
    53     filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#84b3df', endColorstr='#609dd6',GradientType=0 ); /* IE6-9 */
    54 
    55     border-color: #5c9bd5 #3077ba #3077ba #5c9bd5;
    56     border-radius: 2px;
    57     border-style: solid;
    58     border-width: 1px;
    59     box-shadow: 1px 1px 0 rgba(255, 255, 255, 0.15) inset;
    60     color: #fff;
    61     padding: 10px 6px;
    62     cursor: pointer;
    63     text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.15);
     63    color: #ffffff;
     64    border: 1px solid #169ad4;
     65    background: #169ad4;
     66    box-shadow: none;
     67    cursor: pointer;   
     68    text-shadow: none;
    6469    white-space: nowrap;
     70    margin-bottom: 13px;
     71    font: normal 600 14px / 16px "Open Sans", Helvetica, Arial, Verdana, sans-serif;
     72    text-transform: none;
     73    -webkit-border-radius: 3px;
     74    border-radius: 3px;
     75    padding: 0 18px;
     76    min-height: 40px;
     77    line-height: 40px;
    6578}
    6679
    67 .cyclosNewCaptcha {
    68     display: block;
    69     float: right;   
    70     line-height: 12px;
    71     margin-top: 18px;
    72    
     80.cyclosNewCaptcha {       
     81    margin-top: 9px;   
    7382}
    7483
Note: See TracChangeset for help on using the changeset viewer.