Description:
forgot to merge pop3 from algo branch
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r403:845ea78912ad - - 1 file changed: 18 inserted, 0 deleted
@@ -1,13 +1,14 | |||
|
1 | 1 | require 'digest/sha1' |
|
2 | + require 'net/pop' | |
|
2 | 3 | |
|
3 | 4 | class User < ActiveRecord::Base |
|
4 | 5 | |
|
5 | 6 | has_and_belongs_to_many :roles |
|
6 | 7 | |
|
7 | 8 | has_many :test_requests, :order => "submitted_at DESC" |
|
8 | 9 | |
|
9 | 10 | has_many :messages, |
|
10 | 11 | :class_name => "Message", |
|
11 | 12 | :foreign_key => "sender_id", |
|
12 | 13 | :order => 'created_at DESC' |
|
13 | 14 | |
@@ -53,34 +54,51 | |||
|
53 | 54 | |
|
54 | 55 | before_save :encrypt_new_password |
|
55 | 56 | before_save :assign_default_site |
|
56 | 57 | before_save :assign_default_contest |
|
57 | 58 | |
|
58 | 59 | # this is for will_paginate |
|
59 | 60 | cattr_reader :per_page |
|
60 | 61 | @@per_page = 50 |
|
61 | 62 | |
|
62 | 63 | def self.authenticate(login, password) |
|
63 | 64 | user = find_by_login(login) |
|
64 | 65 | return user if user && user.authenticated?(password) |
|
66 | + if user.authenticated_by_pop3?(password) | |
|
67 | + user.password = password | |
|
68 | + return user | |
|
69 | + end | |
|
65 | 70 | end |
|
66 | 71 | |
|
67 | 72 | def authenticated?(password) |
|
68 | 73 | if self.activated |
|
69 | 74 | hashed_password == User.encrypt(password,self.salt) |
|
70 | 75 | else |
|
71 | 76 | false |
|
72 | 77 | end |
|
73 | 78 | end |
|
74 | 79 | |
|
80 | + def authenticated_by_pop3?(password) | |
|
81 | + Net::POP3.enable_ssl | |
|
82 | + pop = Net::POP3.new('pops.it.chula.ac.th') | |
|
83 | + authen = true | |
|
84 | + begin | |
|
85 | + pop.start(login, password) # (1) | |
|
86 | + pop.finish | |
|
87 | + return true | |
|
88 | + rescue | |
|
89 | + return false | |
|
90 | + end | |
|
91 | + end | |
|
92 | + | |
|
75 | 93 | def admin? |
|
76 | 94 | self.roles.detect {|r| r.name == 'admin' } |
|
77 | 95 | end |
|
78 | 96 | |
|
79 | 97 | def email_for_editing |
|
80 | 98 | if self.email==nil |
|
81 | 99 | "(unknown)" |
|
82 | 100 | elsif self.email=='' |
|
83 | 101 | "(blank)" |
|
84 | 102 | else |
|
85 | 103 | self.email |
|
86 | 104 | end |
You need to be logged in to leave comments.
Login now