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