class Wikicr::Users

Overview

The class Users handles a list of User, with add, remove, update an find operation. An instance of Users must be linked with a file which can be read of updated

TODO mutex on add/remove/update

Included Modules

Defined in:

lib/users/users.cr

Constructors

Instance Method Summary

Instance methods inherited from class Lockable

load! load!, save! save!, transaction!(read = false, &) transaction!

Constructor Detail

def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) #

[View source]
def self.new(file : String, default : User | Nil = nil) #

[View source]

Instance Method Detail

def [](name : String) : User #

[View source]
def []?(name : String) : User | Nil #

[View source]
def add(u : User) #

add an user to the list


[View source]
def auth!(name : String, password : String) : User | Nil #

Operation read (erase the internal list).

see #auth?


[View source]
def auth?(name : String, password : String) : User | Nil #

No file operation.

Finds an user by its name and check the password.

Returns nil if it fails


[View source]
def auth_token!(name : String, token : String) : User | Nil #

[View source]
def auth_token?(name : String, token : String) : User | Nil #

[View source]
def default : User | Nil #

[View source]
def default=(default : User | Nil) #

[View source]
def delete(u : User) #

Removes an user from the list @see #delete(String)


[View source]
def delete(name : String) #

Remove an user from the list


[View source]
def each(&) #

[View source]
def file : String #

[View source]
def file=(file : String) #

[View source]
def find(name : String) : User #

find an user based on its name


[View source]
def find?(name : String) : User | Nil #

find an user based on its name


[View source]
def list : Hash(String, User) #

[View source]
def list=(list : Hash(String, User)) #

[View source]
def load! #

read the users from the file (erase the modifications !)


[View source]
def map(&) #

[View source]
def map!(&) #

[View source]
def register!(name : String, password : String, groups : Array(String) = ["user"] of ::String) #

Operation read and write (erase the internal list and the file)

Registers a new user by create a new User with name, password and groups and then update the file with the new list of users.


[View source]
def save! #

save the users into the file


[View source]
def update(name : String, u : User) #

replace an entry


[View source]