#encoding:utf-8
class AdminController < AdminBaseController
  skip_before_action :check_user_status, only: :user_not_enabled

  def index
    @total_device_count = DataOverview.total_device_count
    @online_device_count = DataOverview.online_device_count
    @totoal_h2_amount = DataOverview.totoal_h2_amount
    if current_user.has_unsafe_password?
      @unsafe_password = true  # Later this should moved to a before action
    end
  end

  def user_not_enabled

  end

  def overview
  end

  def account
    @user = current_user
  end

  def account_edit
    @user = current_user
  end

  # GET /account/password
  def password
    @user = current_user
  end

  # PUT /account/password
  def update_password
    @user = User.find(current_user.id)
    if @user.update_with_password(user_params)
      flash[:info] = "密码修改成功, 请记住你的新密码"
      # Sign in the user by passing validation in case their password changed
      sign_in @user, :bypass => true
      redirect_to "/account/password"
    else
      render "password"
    end
  end

  private
  def user_params
    # NOTE: Using `strong_parameters` gem
    params.require(:user).permit(:password, :password_confirmation, :current_password)
  end
end
