File: login.php

package info (click to toggle)
php-doc 20081024-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 57,752 kB
  • ctags: 3,858
  • sloc: xml: 686,554; php: 19,446; perl: 610; cpp: 500; makefile: 336; sh: 114; awk: 28
file content (130 lines) | stat: -rw-r--r-- 4,193 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/*
  +----------------------------------------------------------------------+
  | PHP Version 4                                                        |
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2008 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.0 of the PHP license,       |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_0.txt.                                  |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | license@php.net so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Authors : Salah Faya <visualmind@php.net>                            |
  +----------------------------------------------------------------------+

*/
//-- The PHPDOC Online XML Editing Tool 
//--- Purpose: allows users to login using an email address (TODO we may use CVS or other way in future)

//------- Initialization
require 'base.php';

session_start();

// Logout  &and=logout
if (isset($_GET['and'])) {
		unset($_SESSION['user']);
}


//------- Login request
if (isset($_POST['lang'])) {

	$email = '';
	if (isset($_POST['email'])) {
		$email = $_POST['email'];
	}

	$lang = $_POST['lang'];

	// Check selected language
	if (!isset($phpdocLangs[$lang])) {
		exit('Sorry, you have choosen an incorrect language');
	}

	if ($requireLogin) {
		// Simple email validation -- ToDo some enhancements
		$email = trim(strtolower($email));
		$p1 = preg_match("#^([a-z0-9][a-z0-9_\.]*)@[a-z0-9][a-z0-9\-]+\.[a-z]{2,6}$#", $email);
		$p2 = preg_match("#^([a-z0-9][a-z0-9_\.]*)@[a-z0-9][a-z0-9\-]+\.[a-z]{2,3}\.[a-z]{2}$#", $email);
	
		if (!$p1 && !$p2) {
			exit('That was not a valid email address');
		}
		// This validation is required because emails are used as user folder name -- ToDO use another way
		if (strlen($email)>50) {
			exit('That was not a valid email address');
		}

		// Do Login (create user folder)
		if (!file_exists($usersCachePath.$email)) {
			@mkdir($usersCachePath.$email, $filesChMod);
		}
		
	}
	


	if (is_dir($usersCachePath.$email) || !$requireLogin) {

		// Session setup
		$_SESSION['user'] = array('email'=>$email, 'cache'=>$usersCachePath.$email.'/', 'phpdocLang'=>$lang);

		// If expired session, redo last request
		if (!empty($_SESSION['redo'])) {
			$link = $_SESSION['redo'];
			$_SESSION['redo'] = false;
			header("location: $link");
			exit;
		}

		// If accidently lost session while editing
		if ($_REQUEST['from']=='editxml') {
			exit('Ok, Login is <b>successful</b>. Now retry your previous request');
		}

		// Redirect to frameset
		header('location: workbench.php');
		exit('<a href="workbench.php">Moved to workbench.php</a>');
	} else {
		// If folder has not been created
		exit('Sorry, there was an internal error. Please contact administration');
	}
}

//------- Login form
?>
<html>
<body style="font-family: Tahoma; font-size: 12px;">

<h3> The PHPDOC Online XML Editing Tool :: Choose your language</h3>
<form action=login.php method=post>
<input type=hidden name=from value="<?php print $_REQUEST['from']; ?>">
<?php 
if ($requireLogin) { ?>
Your email address (must be valid) <input type=text name=email><br>
<?php } ?>
Translating PHPDOC to 
<select name=lang><?php
foreach($phpdocLangs as $lang=>$langInfo) {
	print "<option value='$lang'>$lang</option>";
}
?>
</select>* <input type=submit value="Start editing">
</form>

 Developed by Salah Faya visualmind(@)php.net<br> 
 Version 1.0 - essentially developed for Arabic Translation of PHP Manual<br>
 Now updated to work with all phpdoc translations.
<br>
	This is a special tool to be used only by PHPDOC translators.<br>

Javascript and cookies must be enabled in your browser settings.<br>
<br>
<b>Last CVS Update: <?php print implode('', file('cvsupdate.txt')); ?></b>
</body>
</html>