Users
From Yate Documentation
(Difference between revisions)
Line 1: | Line 1: | ||
− | This module configures the database account name and users management (add, update, remove and retrieve queries). | + | This module configures the database account name and users management (add, update, remove and retrieve queries) kept in configuration file: users.conf. |
'''Note:''' All database queries are done with PostgreSQL. | '''Note:''' All database queries are done with PostgreSQL. | ||
===Example of create table users === | ===Example of create table users === | ||
+ | |||
+ | This is an example of creating the users table: | ||
CREATE TABLE users ( | CREATE TABLE users ( | ||
Line 10: | Line 12: | ||
password text, | password text, | ||
); | ); | ||
− | + | ||
− | + | === Configuration file === | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | === Configuration === | + | |
File users.conf | File users.conf | ||
Line 60: | Line 40: | ||
; select_user: string: Database query used to retrieve user's data | ; select_user: string: Database query used to retrieve user's data | ||
;select_user=SELECT * FROM users WHERE username='${user}' | ;select_user=SELECT * FROM users WHERE username='${user}' | ||
+ | |||
+ | |||
+ | ===Example for add_user procedure=== | ||
+ | |||
+ | This is an example of creating a stored procedure for adding a user: | ||
+ | |||
+ | CREATE FUNCTION user_add(text, text) RETURNS integer | ||
+ | AS $_$ | ||
+ | DECLARE | ||
+ | _username ALIAS FOR $1; | ||
+ | _password ALIAS FOR $2; | ||
+ | n integer; | ||
+ | BEGIN | ||
+ | SELECT INTO n COUNT(*) FROM users WHERE username=_username; | ||
+ | IF n > 0 THEN | ||
+ | n := 0; | ||
+ | ELSE | ||
+ | INSERT INTO users (username,password) VALUES (_username,_password); | ||
+ | n := 1; | ||
+ | END IF; | ||
+ | RETURN n; | ||
+ | END; | ||
+ | $_$ | ||
+ | LANGUAGE plpgsql; | ||
===Commands=== | ===Commands=== |
Revision as of 16:47, 4 June 2013
This module configures the database account name and users management (add, update, remove and retrieve queries) kept in configuration file: users.conf.
Note: All database queries are done with PostgreSQL.
Contents |
Example of create table users
This is an example of creating the users table:
CREATE TABLE users ( username text NOT NULL, password text, );
Configuration file
File users.conf
; This file configures the users management module [database] ; This section configures user management database access ; account: string: The name of the database account ;account= ; add_user: string: Database query used to add a new user ; The query should fail if the user already exists ; Extra care must be taken when building this query: undesirable things may happen ; like replacing an existing user's password or adding a duplicate, unreachable, ; entry in the users table ;add_user=SELECT * FROM user_add('${user}','${password}') ; update_user: string: Database query used to update an existing user ;update_user=UPDATE users SET password='${password}' WHERE username='${user}' ; remove_user: string: Database query used to delete an existing user ;remove_user=DELETE FROM users WHERE username='${user}' ; select_user: string: Database query used to retrieve user's data ;select_user=SELECT * FROM users WHERE username='${user}'
Example for add_user procedure
This is an example of creating a stored procedure for adding a user:
CREATE FUNCTION user_add(text, text) RETURNS integer AS $_$ DECLARE _username ALIAS FOR $1; _password ALIAS FOR $2; n integer; BEGIN SELECT INTO n COUNT(*) FROM users WHERE username=_username; IF n > 0 THEN n := 0; ELSE INSERT INTO users (username,password) VALUES (_username,_password); n := 1; END IF; RETURN n; END; $_$ LANGUAGE plpgsql;
Commands
From telnet the command can be used to add/delete/update a user:
users {add user [parameter=value...]|delete user|update user [parameter=value...]}
See also