| 
									
										
										
										
											2008-06-17 09:35:01 -04:00
										 |  |  | <?php | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * Laconica - a distributed open-source microblogging tool | 
					
						
							|  |  |  |  * Copyright (C) 2008, Controlez-Vous, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (!defined('LACONICA')) { exit(1); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-17 10:51:40 -04:00
										 |  |  | require_once(INSTALLDIR.'/lib/openid.php'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:49:23 -05:00
										 |  |  | class OpenidloginAction extends Action | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-06-17 10:49:42 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:33:23 -05:00
										 |  |  |     function handle($args) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         parent::handle($args); | 
					
						
							|  |  |  |         if (common_logged_in()) { | 
					
						
							|  |  |  |             common_user_error(_('Already logged in.')); | 
					
						
							|  |  |  |         } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { | 
					
						
							|  |  |  |             $openid_url = $this->trimmed('openid_url'); | 
					
						
							| 
									
										
										
										
											2008-08-29 00:09:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |             # CSRF protection
 | 
					
						
							|  |  |  |             $token = $this->trimmed('token'); | 
					
						
							|  |  |  |             if (!$token || $token != common_session_token()) { | 
					
						
							|  |  |  |                 $this->show_form(_('There was a problem with your session token. Try again, please.'), $openid_url); | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2008-08-28 23:59:34 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |             $rememberme = $this->boolean('rememberme'); | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |             common_ensure_session(); | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |             $_SESSION['openid_rememberme'] = $rememberme; | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |             $result = oid_authenticate($openid_url, | 
					
						
							|  |  |  |                                        'finishopenidlogin'); | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |             if (is_string($result)) { # error message
 | 
					
						
							|  |  |  |                 unset($_SESSION['openid_rememberme']); | 
					
						
							|  |  |  |                 $this->show_form($result, $openid_url); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $openid_url = oid_get_last(); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:21:29 -05:00
										 |  |  |             $this->show_form(null, $openid_url); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-06-17 09:35:01 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:33:23 -05:00
										 |  |  |     function get_instructions() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         return _('Login with an [OpenID](%%doc.openid%%) account.'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-07-01 13:24:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:33:23 -05:00
										 |  |  |     function show_top($error=null) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         if ($error) { | 
					
						
							| 
									
										
										
										
											2009-01-15 22:57:15 +00:00
										 |  |  |             $this->element('div', array('class' => 'error'), $error); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             $instr = $this->get_instructions(); | 
					
						
							|  |  |  |             $output = common_markup_to_html($instr); | 
					
						
							| 
									
										
										
										
											2009-01-15 22:57:15 +00:00
										 |  |  |             $this->elementStart('div', 'instructions'); | 
					
						
							|  |  |  |             $this->raw($output); | 
					
						
							|  |  |  |             $this->elementEnd('div'); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-07-01 13:24:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:33:23 -05:00
										 |  |  |     function show_form($error=null, $openid_url) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-12-23 14:21:29 -05:00
										 |  |  |         common_show_header(_('OpenID Login'), null, $error, array($this, 'show_top')); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         $formaction = common_local_url('openidlogin'); | 
					
						
							| 
									
										
										
										
											2009-01-15 22:57:15 +00:00
										 |  |  |         $this->elementStart('form', array('method' => 'post', | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |                                            'id' => 'openidlogin', | 
					
						
							|  |  |  |                                            'action' => $formaction)); | 
					
						
							| 
									
										
										
										
											2009-01-15 22:57:15 +00:00
										 |  |  |         $this->hidden('token', common_session_token()); | 
					
						
							|  |  |  |         $this->input('openid_url', _('OpenID URL'), | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |                      $openid_url, | 
					
						
							|  |  |  |                      _('Your OpenID URL')); | 
					
						
							| 
									
										
										
										
											2009-01-15 22:57:15 +00:00
										 |  |  |         $this->checkbox('rememberme', _('Remember me'), false, | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |                         _('Automatically login in the future; ' . | 
					
						
							|  |  |  |                            'not for shared computers!')); | 
					
						
							| 
									
										
										
										
											2009-01-15 22:57:15 +00:00
										 |  |  |         $this->submit('submit', _('Login')); | 
					
						
							|  |  |  |         $this->elementEnd('form'); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         common_show_footer(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-06-17 09:35:01 -04:00
										 |  |  | } |