From 31827d94e1e0f9e06b56ff6db49d8d4673338ea5 Mon Sep 17 00:00:00 2001 From: yafeilee Date: Thu, 3 Apr 2014 11:13:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0session=20urlback=20=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/angularjs/admin_sessions.js.coffee | 5 +++-- app/controllers/admin/sessions_controller.rb | 1 + app/controllers/application_controller.rb | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/angularjs/admin_sessions.js.coffee b/app/assets/javascripts/angularjs/admin_sessions.js.coffee index fe70983..2b17a22 100644 --- a/app/assets/javascripts/angularjs/admin_sessions.js.coffee +++ b/app/assets/javascripts/angularjs/admin_sessions.js.coffee @@ -1,4 +1,4 @@ -@app.controller 'AdminSessionsController', [ '$scope', '$http', '$timeout', ($scope, $http, $timeout)-> +@app.controller 'AdminSessionsController', [ '$scope', '$http', '$timeout', '$cookies', ($scope, $http, $timeout, $cookies)-> url = '/admin/sessions' $scope.login = -> @@ -10,7 +10,8 @@ password: $scope.password .success (res)-> if res.success - window.location = '/admin' + urlback = $cookies.urlback || 'admin' + window.location = urlback else $scope.password = '' $scope.error_msg = res.message diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb index b90767e..c422e52 100644 --- a/app/controllers/admin/sessions_controller.rb +++ b/app/controllers/admin/sessions_controller.rb @@ -12,6 +12,7 @@ class Admin::SessionsController < ApplicationController elsif ENV['ADMIN_PASSWORD'] != params[:password] render :json=> { success: false, message: '管理员密码错误' } else + flash[:notice] = '登录成功' session[:login] = true render :json=> { success: true } end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index abbce3f..45c5f31 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -17,6 +17,7 @@ class ApplicationController < ActionController::Base def authericate_user! if ! session[:login] flash[:error] = '请先登录后台管理' + cookies[:urlback] = request.original_url redirect_to new_admin_session_path end end