Flint
Check-in [8ae48d4c11]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add new name validation rule and allow + in email address
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8ae48d4c11d05eb0ec57f527b4761be86a7e0dcd
User & Date: james 2012-06-12 00:46:03
Context
2012-06-12
00:48
Spell check check-in: 02ac16a103 user: james tags: trunk
00:46
Add new name validation rule and allow + in email address check-in: 8ae48d4c11 user: james tags: trunk
2012-05-19
15:50
Use text since it's the resulting datatype used by sqlite anyways check-in: d795104fa6 user: james tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to nano/validation/rules.php.

4
5
6
7
8
9
10

11
12
13
14
15
16
17
..
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
..
56
57
58
59
60
61
62









63
64
65
66
67
68
69
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{
    public static $_rules = array(
        'required'    => '{{field}} is required.',
        'login'       => '{{field}} and password combination is invalid.',
        'email'       => '{{field}} must be a valid email address.',
        'username'    => '{{field}} cannot contain spaces.',
        'alpha'       => '{{field}} must only contain letters.',

        'numeric'     => '{{field}} must only contain numbers.',
        'filename'    => '{{field}} must only contain letters, numbers, underscores and dashes.',
        'length'      => '{{field}} cannot be longer than {{option}} characters.',
        'match'       => '{{field}} does not match {{option}}.',
        'unique'      => '{{field}} is already in use.',
        'uniqueEmail' => '{{field}} is already in use.',
    );
................................................................................
        }

        return false;
    }

    public static function email($val)
    {
        if (preg_match('/^[a-zA-Z0-9._-]+\@[a-z0-9.-]+\.[a-z]{2,6}$/', $val)) {
            return true;
        }

        return false;
    }

    public static function username($val)
................................................................................
    {
        if (preg_match('/^[a-z ]+$/i', $val)) {
            return true;
        }

        return false;
    }










    public static function numeric($val)
    {
        if (preg_match('/^[0-9]+$/', $val)) {
            return true;
        }

................................................................................
            return true;
        }

        return false;
    }

    public static function length($val, $option)
    {   
        if (strlen($val) <= $option) {
            return true;
        }

        return false;
    }








>







 







|







 







>
>
>
>
>
>
>
>
>







 







|







4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
..
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{
    public static $_rules = array(
        'required'    => '{{field}} is required.',
        'login'       => '{{field}} and password combination is invalid.',
        'email'       => '{{field}} must be a valid email address.',
        'username'    => '{{field}} cannot contain spaces.',
        'alpha'       => '{{field}} must only contain letters.',
        'name'        => '{{field}} must only contain letters, spaces and hypens.',
        'numeric'     => '{{field}} must only contain numbers.',
        'filename'    => '{{field}} must only contain letters, numbers, underscores and dashes.',
        'length'      => '{{field}} cannot be longer than {{option}} characters.',
        'match'       => '{{field}} does not match {{option}}.',
        'unique'      => '{{field}} is already in use.',
        'uniqueEmail' => '{{field}} is already in use.',
    );
................................................................................
        }

        return false;
    }

    public static function email($val)
    {
        if (preg_match('/^[a-zA-Z0-9+._-]+\@[a-z0-9.-]+\.[a-z]{2,6}$/', $val)) {
            return true;
        }

        return false;
    }

    public static function username($val)
................................................................................
    {
        if (preg_match('/^[a-z ]+$/i', $val)) {
            return true;
        }

        return false;
    }

    public static function name($val)
    {
        if (preg_match('/^[a-z -]+$/i', $val)) {
            return true;
        }

        return false;
    }

    public static function numeric($val)
    {
        if (preg_match('/^[0-9]+$/', $val)) {
            return true;
        }

................................................................................
            return true;
        }

        return false;
    }

    public static function length($val, $option)
    {
        if (strlen($val) <= $option) {
            return true;
        }

        return false;
    }

Changes to public/secure/create-account.php.

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
$view = new Nano_View();
$view->title(' - Create Account');

if ($_POST) {
    $validation = new Nano_Validation();

    $rules                   = array();
    $rules['first-name']     = 'required,alpha';
    $rules['last-name']      = 'required,alpha';
    $rules['email']          = 'required,email,uniqueEmail';
    $rules['username']       = 'required,username,unique';
    $rules['password']       = 'required';
    $rules['password-again'] = 'required,match[password]';

    if ($validation->validate($_POST, $rules)) {
        $user = array();
        $user['firstname'] = $_POST['first-name'];
        $user['lastname']  = $_POST['last-name'];
        $user['email']     = $_POST['email'];
        $user['username']  = $_POST['username'];
        $user['password']  = $_POST['password'];
        
        if (Nano_Session::create($user)) {
            $_SESSION['new-account'] = true;
            Nano_Session::login($user['username'], $user['password']);
            header('Location: /secure/');
            die();
        }
        else {







|
|












|







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
$view = new Nano_View();
$view->title(' - Create Account');

if ($_POST) {
    $validation = new Nano_Validation();

    $rules                   = array();
    $rules['first-name']     = 'required,name';
    $rules['last-name']      = 'required,name';
    $rules['email']          = 'required,email,uniqueEmail';
    $rules['username']       = 'required,username,unique';
    $rules['password']       = 'required';
    $rules['password-again'] = 'required,match[password]';

    if ($validation->validate($_POST, $rules)) {
        $user = array();
        $user['firstname'] = $_POST['first-name'];
        $user['lastname']  = $_POST['last-name'];
        $user['email']     = $_POST['email'];
        $user['username']  = $_POST['username'];
        $user['password']  = $_POST['password'];

        if (Nano_Session::create($user)) {
            $_SESSION['new-account'] = true;
            Nano_Session::login($user['username'], $user['password']);
            header('Location: /secure/');
            die();
        }
        else {