Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add: 用户可选择是否接受邮件提醒

  • Loading branch information...
commit 304088ffc4a3732f4bc421aa19e716bebc2c9acf 1 parent 0eeac3b
Jason Lee huacnlee authored
9 app/mailers/user_mailer.rb
View
@@ -9,6 +9,8 @@ def welcome(user_id)
# 被关注
def be_followed(user_id, follower_id)
@user = User.find(user_id)
+ # 跳过,如果用户不允许发邮件
+ return if @user.mail_be_followed == false
@follower = User.find(follower_id)
@title = "#{@follower.name}#{Setting.app_name}关注了你"
mail(:to => @user.email,
@@ -19,7 +21,12 @@ def self.new_answer_to_followers(answer_id)
Thread.new {
@answer = Answer.find(answer_id)
@ask = Ask.find(@answer.ask_id)
- emails = @ask.followers.excludes(:id => @answer.user_id).collect { |u| u.email }
+ emails = []
+ @ask.followers.excludes(:id => @answer.user_id).each do |u|
+ # 跳过,如果用户不允许发邮件
+ next if u.mail_new_answer == false
+ emails << u.email
+ end
emails.each do |email|
UserMailer.new_answer(answer_id,email).deliver
end
6 app/models/user.rb
View
@@ -25,6 +25,9 @@ class User
field :followed_ask_ids, :type => Array, :default => []
# 回答过的问题
field :answered_ask_ids, :type => Array, :default => []
+ # Email 提醒的状态
+ field :mail_be_followed, :type => Boolean, :default => true
+ field :mail_new_answer, :type => Boolean, :default => true
# 邀请字段
field :invitation_token
@@ -47,7 +50,7 @@ class User
has_many :logs, :class_name => "Log", :foreign_key => "target_id"
attr_accessor :password_confirmation
- attr_accessible :email, :password,:name, :slug, :tagline, :bio, :avatar, :website, :girl
+ attr_accessible :email, :password,:name, :slug, :tagline, :bio, :avatar, :website, :girl, :mail_new_answer, :mail_be_followed
validates_presence_of :name, :slug
validates_uniqueness_of :slug
@@ -62,6 +65,7 @@ def avatar_small_changed?
end
redis_search_index(:title_field => :name, :ext_fields => [:slug,:avatar_small,:tagline])
+
# 敏感词验证
before_validation :check_spam_words
def check_spam_words
54 app/views/registrations/edit.html.erb
View
@@ -1,28 +1,40 @@
<% content_for :sitemap do %><span class="current">设置</span><% end %>
<div class="leftbox">
-<div class="box">
- <h1>个人资料</h1>
- <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :enctype => "multipart/form-data" }) do |f| %>
- <%= render "shared/error_messages", :target => resource %>
- <%= f.input :slug, :label => "个性域名" %>
- <%= f.input :girl, :as => :boolean, :label => "我是女性" %>
- <%= f.input :email, :label => "邮箱" %>
- <%= f.input :avatar, :label => "头像" %>
- <% if not @user.avatar.blank? %>
- <div class="row">
- <label>预览</label>
- <%= image_tag(@user.avatar.normal.url) %>
- </div>
+ <div class="box">
+ <h2>个人资料</h2>
+ <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :enctype => "multipart/form-data" }) do |f| %>
+ <%= render "shared/error_messages", :target => resource %>
+ <%= f.input :slug, :label => "个性域名" %>
+ <%= f.input :girl, :as => :boolean, :label => "我是女性" %>
+ <%= f.input :email, :label => "邮箱" %>
+ <%= f.input :avatar, :label => "头像" %>
+ <% if not @user.avatar.blank? %>
+ <div class="row">
+ <label>预览</label>
+ <%= image_tag(@user.avatar.normal.url) %>
+ </div>
+ <% end %>
+ <%= f.input :website, :input_html => { :placeholder => "http://", :class => "long" }, :label => "个人站点" %>
+ <%= f.input :tagline, :input_html => { :class => "long" }, :label => "最能概括你的标志性语言" %>
+ <%= f.input :bio, :as => :text, :input_html => { :class => "long", :style => "height:120px;"}, :label => "个人经历" %>
+ <script type="text/javascript">$("#user_bio").qeditor();</script>
+ <div class="actions">
+ <button type="submit">保存</button>
+ </div>
<% end %>
- <%= f.input :website, :input_html => { :placeholder => "http://", :class => "long" }, :label => "个人站点" %>
- <%= f.input :tagline, :input_html => { :class => "long" }, :label => "最能概括你的标志性语言" %>
- <%= f.input :bio, :as => :text, :input_html => { :class => "long", :style => "height:120px;"}, :label => "个人经历" %>
- <script type="text/javascript">$("#user_bio").qeditor();</script>
- <div class="actions">
- <button type="submit">保存</button>
+ </div>
+ <div class="box">
+ <h2>邮件提醒设置</h2>
+ <div class="content">
+ <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :enctype => "multipart/form-data" }) do |f| %>
+ <%= f.input :mail_be_followed, :as => :boolean, :label => "被人关注" %>
+ <%= f.input :mail_new_answer, :as => :boolean, :label => "关注的问题有新回答" %>
+ <div class="actions">
+ <button type="submit">保存</button>
+ </div>
+ <% end %>
</div>
- <% end %>
-</div>
+ </div>
</div>
<% content_for :sidebar do %>
<%= render "/shared/omniauth_links" %>
2  public/stylesheets/front.css
View
@@ -73,6 +73,8 @@ address, blockquote {
.sidebar { float:right; width:210px; overflow:hidden; _width:190px; }
.sidebar .box { margin-bottom:20px; }
.sidebar .box h2 { border-top: 1px dotted silver; padding: 15px 0 3px; color: #333; font-size: 1.2em; margin-bottom: 3px; }
+.leftbox .box h2 { border-top: 1px dotted silver; padding: 15px 0 3px; color: #333; font-size: 1.2em; margin-bottom: 3px; }
+.leftbox .box { margin-bottom:20px; }
.sidebar li { line-height:160%; }
.sidebar .standard ul {
margin: 0;
Please sign in to comment.
Something went wrong with that request. Please try again.