Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/user.rb

Overview

The User class

This is actually based on the user class that is generated automatically by the Login Generator, but I suspect only software historians need to know that. The Login Generator is pretty much universally adapted by anyone writing a Rails application that has users, and this one is no different.

From the schema, the data elements of the User class (because otherwise, they wouldn’t be described anywhere).

domain

The Domain that the user belongs to.

login

The user’s username. This is also the name used for their Sugoi-Mail address.

password

A SHA1-encrypted password hash.

mailinglist

The user’s Mailinglist. The addresses listed in this Mailinglist are the address that any message sent to login@domain is then forwarded to.

domainadmin

Whether the user is a domain administrator or not. This mainly controls the ability to create new users.

mailinglistadmin

Whether they can create, delete, or modify mailing lists.

The User’s email address is actually provided by the Mailinglist that belongs to the user. By adding at least one Address to this Mailinglist, you can forward messages sent to user@sugoi-domain to their real email address. Any message sent from the user’s real address via sugoi-domain has that real email address rewritten to be the sugoi-domain address.

Constant Summary collapse

@@salt =

Please change the salt to something else, Every application should use a different one

'thuchpog10.?guf'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.authenticate(login, pass) ⇒ Object

Authenticate a user.

Example:

@user = User.authenticate('bob', 'bobpass')


84
85
86
# File 'app/models/user.rb', line 84

def self.authenticate(, pass)
     , sha1(pass)
end

Instance Method Details

#addressObject

The mail proxy email address



49
# File 'app/models/user.rb', line 49

def address; "#{mailinglist.name}@#{domain.name}" end

#addressesObject

The list of addresses that mail sent to the user will be forwarded to.



46
# File 'app/models/user.rb', line 46

def addresses; mailinglist.addresses end

#after_createObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/models/user.rb', line 108

def after_create
    ml=Mailinglist.new
    ml.name=self.
    ml.user_id=self.id
    ml.mailinglist_class=MailinglistClass.find 1 # XXX MAGIC CONSTANT XXX
    if @description then
        ml.description = @description
    end
    if ml.save then
        self.mailinglist=ml
        self.password = self.password_confirmation
        self.save
        return true
    end
end

#before_destroyObject



124
125
126
127
128
129
130
# File 'app/models/user.rb', line 124

def before_destroy
    ml=self.mailinglist
    if ml
        ml.destroy
    end
    self.mailinglist_id = nil
end

#descriptionObject

The user’s “description”–if the user’s a person, this would be their real name.



54
55
56
57
58
59
60
# File 'app/models/user.rb', line 54

def description
    if new_record?
        @description
    else
        mailinglist.description 
    end
end

#description=(new_description) ⇒ Object

Change the user’s description. (Actually changes the user’s Mailinglist’s description.)



64
65
66
67
68
69
70
71
72
# File 'app/models/user.rb', line 64

def description=(new_description)
    if new_record?
        @description = new_description
    else
        m=mailinglist
        m.description = new_description
        m.save
    end
end