File: lib.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (154 lines) | stat: -rw-r--r-- 3,958 bytes parent folder | download | duplicates (2)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php  // $Id: lib.php,v 1.2 2005/05/16 19:21:35 stronk7 Exp $
       
// FirstClass authentication using FirstClass Flexible Provisining Protocol

/* Author: Torsten Anderson, torsten.anderson@skeria.skelleftea.se

CHANGELOG

README
  Module will authenticate user against FirstClass server and check if user belongs to any of
  the defined creator groups.
  User authenticates using their existing FirstClass username and password.
  Where possible userdata is copied from the FirstClass directory to Moodle. You may
  want to modify this.
  Module requires the fcFPP class to do it's jobb.
 */
       

require('fcFPP.php');
   

function auth_user_login ($username, $password) {
/// Returns true if the username and password work
/// and false if they don't

    global $CFG;

    $hostname = $CFG->auth_fchost;
    $port     = $CFG->auth_fcfppport;

    $retval = FALSE;

    if (!$username or !$password) {    // Don't allow blank usernames or passwords
        return $retval;
    }


    $fpp = new fcFPP($hostname,$port);
    if ($fpp->open()) {
       if ($fpp->login($username,$password)){
          $retval = TRUE;
       }
    }
    $fpp->close();

    return $retval;
 

}

function auth_get_userinfo($username){
// Get user information from FirstCLass server and return it in an array.
// Localize this routine to fit your needs. 

/*
Moodle                FirstCLass fieldID in UserInfo form
------                -----------------------------------
firstname             1202
lastname              1204
email                 1252
icq                   -
phone1                1206
phone2                1207 (Fax)
institution           -  
department            - 
address               1205
city                  - 
country               -
lang                  -
timezone              8030 (Not used yet. Need to figure out how FC codes timezones)

description           Get data from users resume. Pictures will be removed.

*/

    global $CFG;
    
    $hostname = $CFG->auth_fchost;
    $port     = $CFG->auth_fcfppport;
    $userid   = $CFG->auth_fcuserid;
    $passwd   = $CFG->auth_fcpasswd; 

    $userinfo = array();

    $fpp = new fcFPP($hostname,$port);
    if ($fpp->open()) {
       if ($fpp->login($userid,$passwd)){

          $userinfo['firstname']   = $fpp->getUserInfo($username,"1202");
          $userinfo['lastname']    = $fpp->getUserInfo($username,"1204");
          $userinfo['email']       = strtok($fpp->getUserInfo($username,"1252"),',');
          $userinfo['phone1']      = $fpp->getUserInfo($username,"1206");
          $userinfo['phone2']      = $fpp->getUserInfo($username,"1207");
          $userinfo['description'] = $fpp->getResume($username);

       }
    }

    $fpp->close();

    foreach($userinfo as $key => $value) {
       if (!$value) {
          unset($userinfo[$key]);
       }
    }
    
    return $userinfo;

}


function auth_iscreator($username=0) {
//Get users group membership from the FirstClass server user and check if
// user is member of one of the groups of creators.

    global $CFG, $USER;

    if (! $CFG->auth_fccreators) {
       return false;
    }

    if (! $username) {
       $username=$USER->username;
    }

    $fcgroups = array();

    $hostname = $CFG->auth_fchost;
    $port     = $CFG->auth_fcfppport;
    $userid   = $CFG->auth_fcuserid;
    $passwd   = $CFG->auth_fcpasswd; 

    $fpp = new fcFPP($hostname,$port);
    if ($fpp->open()) {
       if ($fpp->login($userid,$passwd)){
          $fcgroups = $fpp->getGroups($username);
       }
    }
    $fpp->close();

   
    if ((! $fcgroups)) {
      return false;
    }

    $creators = explode(";",$CFG->auth_fccreators);
   
    foreach($creators as $creator) {
        If (in_array($creator, $fcgroups)) return true;
    }
    
    return false;
}