Commit cc93f775 authored by o@immerda.ch's avatar o@immerda.ch
Browse files

add app specific password page

parent 75848a81
// Place all the styles related to the app_passwords controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class AppPasswordsController < ApplicationController
def show
res = ApiBackend::app_passwords(current_user)
if res && res['result'] == 'success'
@passwords = res['names']
if session[:app_pw]
@app_pw = session[:app_pw]
session[:app_pw] = nil
end
else
redirect_to '/'
end
end
def edit
if params[:app_name]
res = ApiBackend::app_password_create(
current_user, params[:password], params[:app_name])
if res && res['result'] == 'success'
session[:app_pw] = res['app_pw']
else
flash[:notice] = :failed
end
elsif params[:delete]
ApiBackend::app_password_delete(current_user, params[:delete])
else
flash[:notice] = :failed
redirect_to '/'
end
redirect_to '/app_passwords'
end
end
......@@ -19,6 +19,11 @@ class ApplicationController < ActionController::Base
end
helper_method :current_user
def trees_enabled?
session[:trees_enabled]
end
helper_method :trees_enabled?
def admin?
@is_admin ||= Admin::Enabled && Admin::Admins.include?(current_user)
end
......
......@@ -62,6 +62,21 @@ module ApiBackend
false
end
def self.app_passwords(email)
get(["app_passwords"], {'email' => email})
end
def self.app_password_delete(email, pw_name)
post(["app_password_delete"], {'email' => email,
'pw_name' => pw_name})
end
def self.app_password_create(email, pw, pw_name)
post(["app_password_create"], {'email' => email,
'password' => pw,
'pw_name' => pw_name})
end
def self.user_info(id)
get(["info"], {'id' => id})
end
......
class TreesController < ApplicationController
def redirect
if session[:trees_enabled]
if trees_enabled?
if session[:trees_token_present] &&
!session[:trees_recovery_token]
redirect_to '/trees_token/request'
......
module AppPasswordsHelper
end
<% if @passwords && !@passwords.empty? %>
<h3><%= t :app_passwords %></h3>
<% if @app_pw %>
<b> <%= t(:your_app_pw_is) %> </b>
<p><%= @app_pw %></p>
<% end %>
<ul>
<% @passwords.each do |pw| %>
<li>
<%= pw %>
<%= form_tag("/app_passwords", method: "post") do %>
<%= hidden_field_tag(:delete, '', value: pw) %>
<%= submit_tag(t :delete) %>
<% end %>
</li>
<% end %>
</ul>
<% end %>
<h3><%= t :new_app_passwords %></h3>
<%= form_tag("/app_passwords", method: "post") do %>
<table>
<tr><td>
<%= label_tag(:app_name, (t :app_name)) %>
</td><td>
<%= text_field_tag(:app_name, '', value: t(:app_name), autocomplete: 'off') %>
</td></tr><tr><td>
<%= label_tag(:password, (t :confirm_pw)) %>
</td><td>
<%= password_field_tag(:password) %>
</td></tr>
</table>
<p>
<%= submit_tag(t :submit) %>
<%= link_to "Cancel", :back %>
</p>
<% end %>
<ul class="menu">
<li><%= link_to (t :change_password), password_path %></li>
<li><%= link_to (t :trees_settings) , trees_path %> (beta)</li>
<% if trees_enabled? %>
<li><%= link_to (t :app_passwords) , app_passwords_path %></li>
<% end %>
<% if admin? %>
<li><%= link_to (t :admin_page) , admin_path %></li>
<% end %>
......
......@@ -36,3 +36,5 @@ de:
unlock: "entsperren"
update: "aktualisieren"
delete: "löschen"
app_name: "Programmname"
your_app_pw_is: "Dein neues App Passwort lautet: "
......@@ -34,3 +34,4 @@ en:
unlock: "unlock"
update: "update"
delete: "delete"
your_app_pw_is: "Your new app password is: "
......@@ -10,6 +10,9 @@ Rails.application.routes.draw do
get '/trees_token', to: 'trees_token#show'
post '/trees_token', to: 'trees_token#destroy'
get '/app_passwords', to: 'app_passwords#show'
post '/app_passwords', to: 'app_passwords#edit'
get '/login', to: 'sessions#new'
post '/login', to: 'sessions#create'
get '/logout', to: 'sessions#destroy'
......
require 'test_helper'
class AppPasswordsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment