Skip to content

Instantly share code, notes, and snippets.

View srockstyle's full-sized avatar

Shohei Kobayashi srockstyle

View GitHub Profile
@srockstyle
srockstyle / rails_myself_auth_routes.rb
Created August 23, 2018 21:24
Railsで自前認証 / routes
Rails.application.routes.draw do
## マイページ
# get 'mypage', to: 'users#index '
## ユーザ
get 'mypage', to: 'users#show'
get '/users/new', to: 'users#new'
post '/users/create', to: 'users#create'
delete '/users/unsubscribe', to: 'usesrs#destroy'
@srockstyle
srockstyle / rails_myself_auth_session_new_form.slim
Created August 23, 2018 21:20
Railsで自前認証 / view / form
h2 ログイン
= form_for :session ,url: login_path do |f|
.field
= f.text_field :mailaddr,class:"input",type:"email"
.field
= f.password_field :password,class:"input"
= f.submit 'ログイン',class: "button is-success"
= link_to 'アカウントを持っていない方は->新規登録', users_new_url
@srockstyle
srockstyle / rails_myself_auth_users_new_form.slim
Created August 23, 2018 21:17
Railsで自前認証 / view / ユーザ管理作成
= form_for @user,url: users_create_url do |f|
- if @user.errors.any?
#error_explanation
h2 = "#{pluralize(@user.errors.count, "error")} prohibited this user from being saved:"
ul
- @user.errors.full_messages.each do |message|
li = message
.field
= f.label :name
@srockstyle
srockstyle / rails_myself_auth_application_controllers.rb
Created August 23, 2018 21:13
Railsで自前認証 / controller / application_controller
class ApplicationController < ActionController::Base
before_action :current_user
before_action :require_sign_in!
helper_method :signed_in?
protect_from_forgery with: :exception
def current_user
remember_token = User.encrypt(cookies[:user_remember_token])
@srockstyle
srockstyle / rails_myself_auth_session_controllers.rb
Created August 23, 2018 21:10
Railsで自前認証 / controller / セッション管理周り
class SessionsController < ApplicationController
def new
end
def create
if @user.authenticate(session_params[:password])
sign_in(@user)
redirect_to mypage_url
else
flash.now[:danger] = t('.flash.invalid_password')
@srockstyle
srockstyle / rails_myself_auth_users_controllers.rb
Created August 23, 2018 21:06
Railsで自前認証 / controller / ユーザ管理周り
class UsersController < ApplicationController
# サインアップ
def new
@user = User.new
end
## 新規登録
def create
@user = User.new(user_params)
if @user.save
@srockstyle
srockstyle / rails_myself_auth_model.rb
Created August 23, 2018 21:01
Railsで自前認証 / model編
class User < ApplicationRecord
has_secure_password validations: true
validates :mailaddr, presence: true, uniqueness: true
def self.new_remember_token
SecureRandom.urlsafe_base64
end
def self.encrypt(token)
@srockstyle
srockstyle / file0.txt
Created November 13, 2017 10:10
【RailsユーザのためのPHP/Laravel】form_for的なのを使いたい ref: https://qiita.com/srockstyle/items/ee8f63d93b871424ccbf
composer require laravelcollective/html
@srockstyle
srockstyle / file0.txt
Last active February 5, 2016 01:10
Let's EncryptのSSL証明書を使ってお手軽HTTP/2対応 ref: http://qiita.com/srockstyle/items/b645e096d73f302b7177
The server could not connect to the client to verify the domain :: Failed to connect to host for DVSNI challenge, <your-domain-name> (tls-sni-01): urn:acme:error:connection :: The server could not connect to the client to verify the domain :: Failed to connect to host for DVSNI challenge
IMPORTANT NOTES:
- The following errors were reported by the server:
Domain: <your-domain-name>
Type: urn:acme:error:connection
Detail: Failed to connect to host for DVSNI challenge
@srockstyle
srockstyle / file0.txt
Last active November 2, 2015 19:58
【RailsユーザのためのPHP/Laravel】よくつかうコマンド入門 ref: http://qiita.com/srockstyle/items/f2c4f29dd92551030dde
php artisan make:migration create_articles_table