From 8190403380cebdff4bbe2b21a46298670b88c33b Mon Sep 17 00:00:00 2001 From: z9hang Date: Thu, 12 Mar 2015 16:33:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?app=E6=B7=BB=E5=8A=A0=E5=BF=98=E8=AE=B0?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E6=8E=A5=E5=8F=A3=EF=BC=8C=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E6=8E=A5=E5=8F=A3=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=88=E5=8E=BB=E6=8E=89=E5=85=B6=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E4=B8=AD=E6=96=87=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/auth.rb | 11 +++++++++++ app/services/courses_service.rb | 9 ++++----- app/services/users_service.rb | 22 ++++++++++++++++++++++ db/schema.rb | 2 +- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/app/api/mobile/apis/auth.rb b/app/api/mobile/apis/auth.rb index 320497e50..fbec9a3b0 100644 --- a/app/api/mobile/apis/auth.rb +++ b/app/api/mobile/apis/auth.rb @@ -40,6 +40,17 @@ module Mobile {status: 0} end + desc "忘记密码" + params do + requires :mail,type: String + end + post 'lost_password' do + us = UsersService.new + message = us.lost_password params + present :message, message + present :status, 0 + end + end end end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 09cc5d59d..c9ea1ca80 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -1,4 +1,3 @@ -#coding=utf-8 class CoursesService include ApplicationHelper include CoursesHelper @@ -355,19 +354,19 @@ class CoursesService latest_course_dynamics = [] latest_news = course.news.order("created_on desc").first unless latest_news.nil? - latest_course_dynamics << {:type => 1,:time => latest_news.created_on,:message => '最近更新了通知' }#l(:label_recently_updated_notification,:locale => current_user.language.nil? ? 'zh':current_user.language)} + latest_course_dynamics << {:type => 1,:time => latest_news.created_on,:message => l(:label_recently_updated_notification,:locale => current_user.language.nil? ? 'zh':current_user.language)} end latest_message = course.journals_for_messages.order("created_on desc").first unless latest_message.nil? - latest_course_dynamics << {:type => 2,:time => latest_message.created_on,:message => '最近更新了留言'}#l(:label_recently_updated_message,:locale => current_user.language.nil? ? 'zh':current_user.language)} + latest_course_dynamics << {:type => 2,:time => latest_message.created_on,:message => l(:label_recently_updated_message,:locale => current_user.language.nil? ? 'zh':current_user.language)} end latest_attachment = course.attachments.order("created_on desc").first unless latest_attachment.nil? - latest_course_dynamics << {:type => 3,:time => latest_attachment.created_on,:message => '最近更新了课件'}#l(:label_recently_updated_courseware,:locale => current_user.language.nil? ? 'zh':current_user.language)} + latest_course_dynamics << {:type => 3,:time => latest_attachment.created_on,:message => l(:label_recently_updated_courseware,:locale => current_user.language.nil? ? 'zh':current_user.language)} end latest_bid = course.homeworks.order('updated_on DESC').first unless latest_bid.nil? - latest_course_dynamics << {:type => 4,:time => latest_bid.updated_on,:message => '最近更新了作业'}#l(:label_recently_updated_homework,:locale => current_user.language.nil? ? 'zh':current_user.language)} + latest_course_dynamics << {:type => 4,:time => latest_bid.updated_on,:message => l(:label_recently_updated_homework,:locale => current_user.language.nil? ? 'zh':current_user.language)} end #每个作业中的最新留言 messages = [] diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 8cadf031c..f75a84c5b 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -80,6 +80,28 @@ class UsersService {:id => @user.id, :img_url => img_url, :nickname => @user.login, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extensions.brief_introduction} end + #忘记密码 + def lost_password params + user = ::User.find_by_mail(params[:mail].to_s) + # user not found or not active + unless user && user.active? + raise l(:notice_account_unknown_email,:locale => 'zh') + end + # user cannot change its password + unless user.change_password_allowed? + raise l(:notice_can_t_change_password,:locale => user.language) + return + end + # create a new token for password recovery + token = Token.new(:user => user, :action => "recovery") + if token.save + Thread.new do + Mailer.lost_password(token).deliver + end + return l(:notice_account_lost_email_sent,:locale => user.language) + end + end + #编辑用户 #gender 1:female 0:male 其他:male def edit_user params diff --git a/db/schema.rb b/db/schema.rb index bad1cf2ae..4cce0b5c8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150305081132) do +ActiveRecord::Schema.define(:version => 20150311013036) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false From b809e8844cbddd7cae32c9c2631bd9448705f58e Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 12 Mar 2015 16:42:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E4=B8=AD=E6=B7=BB=E5=8A=A0=E6=A0=87=E7=AD=BE=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/layouts/base_projects.html.erb | 2 +- app/views/layouts/base_users.html.erb | 2 +- app/views/tags/_project_tag.html.erb | 22 +++++++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/views/layouts/base_projects.html.erb b/app/views/layouts/base_projects.html.erb index 4f5e10990..69c37d2b3 100644 --- a/app/views/layouts/base_projects.html.erb +++ b/app/views/layouts/base_projects.html.erb @@ -123,7 +123,7 @@ <%= link_to "#{@project.members.count}", project_member_path(@project), :style => "color:#3CA5C6;font-weight:bold" %>) | <%= l(:label_user_watcher) %>( - <%= link_to "#{@project.watcher_users.count}", :controller=>"projects", :action=>"watcherlist", :id => @project, :style => "color:#3CA5C6;font-weight:bold" %>) + <%= link_to "#{@project.watcher_users.count}", {:controller=>"projects", :action=>"watcherlist", :id => @project.id}, :style => "color:#3CA5C6;font-weight:bold" %>) | <%= l(:project_module_attachments) %>( <%= link_to "#{@project.attachments.count}", project_files_path(@project), :style => "color:#3CA5C6;font-weight:bold" %>) diff --git a/app/views/layouts/base_users.html.erb b/app/views/layouts/base_users.html.erb index a7ed0aa25..3f483c18d 100644 --- a/app/views/layouts/base_users.html.erb +++ b/app/views/layouts/base_users.html.erb @@ -217,7 +217,7 @@ <% end %> - <% unless @user.user_extensions.location.empty?%> + <% unless @user.user_extensions.location.blank? %> diff --git a/app/views/tags/_project_tag.html.erb b/app/views/tags/_project_tag.html.erb index 75e2ee801..8694d69ca 100644 --- a/app/views/tags/_project_tag.html.erb +++ b/app/views/tags/_project_tag.html.erb @@ -2,19 +2,31 @@ <%= render :partial => "tags/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %> <% if User.current.logged? %> - <%= toggle_link ("+"+l(:label_add_tag)), 'put-tag-form', {:focus => 'tags_name'} %> + <%= toggle_link (l(:label_add_tag)), 'put-tag-form', {:focus => 'tags_name'} %> <% end %>