glacier-web-cli 0.5.0

Command-line tool for creating and running Glacier applications.
# The second step of signing in, for users with two-factor sign-in on: a
# code from their authenticator app, or a recovery code. Written by
# `glacier generate authentication`; it's your code now.
module TwoFactorChallengesController do
  implements Controller
  alias Auth

  def new(ctx) do
    case Auth.second_factor_user(&ctx)! do
      Some(_) -> render alert: "", title: "Two-factor sign-in"
      nil -> redirect new_session_path(), alert: "Sign in again."
    end
  end

  def create(ctx) do
    case Auth.second_factor_user(&ctx)! do
      Some(found) ->
        user = found
        if user.verify_second_factor(&params[:code])! do
          Auth.finish_second_factor(&ctx, &user)!
          redirect Auth.after_sign_in_path(&ctx), notice: "Signed in."
        else
          render :new, alert: "That code isn't right.", title: "Two-factor sign-in", status: 422
        end
      nil -> redirect new_session_path(), alert: "Sign in again."
    end
  end
end