Subversion Repositories oidplus

Rev

Rev 320 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 320 Rev 321
Line 21... Line 21...
21
 
21
 
22
        private static function getFreeRootOid($with_ns) {
22
        private static function getFreeRootOid($with_ns) {
23
                return ($with_ns ? 'oid:' : '').OIDplus::config()->getValue('freeoid_root_oid');
23
                return ($with_ns ? 'oid:' : '').OIDplus::config()->getValue('freeoid_root_oid');
24
        }
24
        }
25
 
25
 
26
        public function action(&$handled) {
26
        public function action($actionID, $params) {
27
                if (empty(self::getFreeRootOid(false))) return;
27
                if (empty(self::getFreeRootOid(false))) throw new OIDplusException("FreeOID service not available. Please ask your administrator.");
28
 
28
 
29
                if (isset($_POST["action"]) && ($_POST["action"] == "request_freeoid")) {
29
                if ($actionID == 'request_freeoid') {
30
                        $handled = true;
-
 
31
                        $email = $_POST['email'];
30
                        $email = $params['email'];
32
 
31
 
33
                        $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email));
32
                        $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email));
34
                        if ($res->num_rows() > 0) {
33
                        if ($res->num_rows() > 0) {
35
                                throw new OIDplusException('This email address already exists.'); // TODO: actually, the person might have something else (like a DOI) and want to have a FreeOID
34
                                throw new OIDplusException('This email address already exists.'); // TODO: actually, the person might have something else (like a DOI) and want to have a FreeOID
36
                        }
35
                        }
Line 39... Line 38...
39
                                throw new OIDplusException('Invalid email address');
38
                                throw new OIDplusException('Invalid email address');
40
                        }
39
                        }
41
 
40
 
42
                        if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) {
41
                        if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) {
43
                                $secret=OIDplus::baseConfig()->getValue('RECAPTCHA_PRIVATE', '');
42
                                $secret=OIDplus::baseConfig()->getValue('RECAPTCHA_PRIVATE', '');
44
                                $response=$_POST["captcha"];
43
                                $response=$params["captcha"];
45
                                $verify=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
44
                                $verify=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
46
                                $captcha_success=json_decode($verify);
45
                                $captcha_success=json_decode($verify);
47
                                if ($captcha_success->success==false) {
46
                                if ($captcha_success->success==false) {
48
                                        throw new OIDplusException('Captcha wrong');
47
                                        throw new OIDplusException('Captcha wrong');
49
                                }
48
                                }
Line 61... Line 60...
61
                        $message = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $message);
60
                        $message = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $message);
62
                        $message = str_replace('{{ACTIVATE_URL}}', $activate_url, $message);
61
                        $message = str_replace('{{ACTIVATE_URL}}', $activate_url, $message);
63
                        OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title').' - Free OID request', $message, OIDplus::config()->getValue('global_cc'));
62
                        OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title').' - Free OID request', $message, OIDplus::config()->getValue('global_cc'));
64
 
63
 
65
                        echo json_encode(array("status" => 0));
64
                        echo json_encode(array("status" => 0));
66
                }
-
 
67
 
65
 
68
                if (isset($_POST["action"]) && ($_POST["action"] == "activate_freeoid")) {
66
                } else if ($actionID == 'activate_freeoid') {
69
                        $handled = true;
-
 
70
 
67
 
71
                        $password1 = $_POST['password1'];
68
                        $password1 = $params['password1'];
72
                        $password2 = $_POST['password2'];
69
                        $password2 = $params['password2'];
73
                        $email = $_POST['email'];
70
                        $email = $params['email'];
74
 
71
 
75
                        $ra_name = $_POST['ra_name'];
72
                        $ra_name = $params['ra_name'];
76
                        $url = $_POST['url'];
73
                        $url = $params['url'];
77
                        $title = $_POST['title'];
74
                        $title = $params['title'];
78
 
75
 
79
                        $auth = $_POST['auth'];
76
                        $auth = $params['auth'];
80
                        $timestamp = $_POST['timestamp'];
77
                        $timestamp = $params['timestamp'];
81
 
78
 
82
                        if (!OIDplus::authUtils()::validateAuthKey('com.viathinksoft.freeoid.activate_freeoid;'.$email.';'.$timestamp, $auth)) {
79
                        if (!OIDplus::authUtils()::validateAuthKey('com.viathinksoft.freeoid.activate_freeoid;'.$email.';'.$timestamp, $auth)) {
83
                                throw new OIDplusException('Invalid auth key');
80
                                throw new OIDplusException('Invalid auth key');
84
                        }
81
                        }
85
 
82
 
Line 156... Line 153...
156
                        $message = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $message);
153
                        $message = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $message);
157
                        $message = str_replace('{{NEW_OID}}', $new_oid, $message);
154
                        $message = str_replace('{{NEW_OID}}', $new_oid, $message);
158
                        OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title').' - Free OID allocated', $message, OIDplus::config()->getValue('global_cc'));
155
                        OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title').' - Free OID allocated', $message, OIDplus::config()->getValue('global_cc'));
159
 
156
 
160
                        echo json_encode(array("status" => 0));
157
                        echo json_encode(array("status" => 0));
-
 
158
                } else {
-
 
159
                        throw new OIDplusException("Unknown action ID");
161
                }
160
                }
162
        }
161
        }
163
 
162
 
164
        public function init($html=true) {
163
        public function init($html=true) {
165
                OIDplus::config()->prepareConfigKey('freeoid_root_oid', 'Root-OID of free OID service (a service where visitors can create their own OID using email verification)', '', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
164
                OIDplus::config()->prepareConfigKey('freeoid_root_oid', 'Root-OID of free OID service (a service where visitors can create their own OID using email verification)', '', OIDplusConfig::PROTECTION_EDITABLE, function($value) {