Commit 257b84a6 by Mykhailo Makohin

finish registration via google

parent 07bf996d
...@@ -5,51 +5,29 @@ git_source(:github) do |repo_name| ...@@ -5,51 +5,29 @@ git_source(:github) do |repo_name|
"https://github.com/#{repo_name}.git" "https://github.com/#{repo_name}.git"
end end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.7', '>= 5.0.7.2' gem 'rails', '~> 5.0.7', '>= 5.0.7.2'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.18', '< 0.6.0' gem 'mysql2', '>= 0.3.18', '< 0.6.0'
# Use Puma as the app server
gem 'puma', '~> 3.0' gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0' gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0' gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2' gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails' gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5' gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5' gem 'jbuilder', '~> 2.5'
gem 'devise' gem 'devise'
gem 'omniauth'
gem 'omniauth-facebook' gem 'omniauth-facebook'
# Use Redis adapter to run Action Cable in production gem 'omniauth-google-oauth2'
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri gem 'byebug', platform: :mri
end end
group :development do group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0' gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.0.5' gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring' gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0' gem 'spring-watcher-listen', '~> 2.0.0'
end end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
...@@ -105,6 +105,10 @@ GEM ...@@ -105,6 +105,10 @@ GEM
rack (>= 1.6.2, < 3) rack (>= 1.6.2, < 3)
omniauth-facebook (5.0.0) omniauth-facebook (5.0.0)
omniauth-oauth2 (~> 1.2) omniauth-oauth2 (~> 1.2)
omniauth-google-oauth2 (0.8.0)
jwt (>= 2.0)
omniauth (>= 1.1.1)
omniauth-oauth2 (>= 1.6)
omniauth-oauth2 (1.6.0) omniauth-oauth2 (1.6.0)
oauth2 (~> 1.1) oauth2 (~> 1.1)
omniauth (~> 1.9) omniauth (~> 1.9)
...@@ -198,7 +202,9 @@ DEPENDENCIES ...@@ -198,7 +202,9 @@ DEPENDENCIES
jquery-rails jquery-rails
listen (~> 3.0.5) listen (~> 3.0.5)
mysql2 (>= 0.3.18, < 0.6.0) mysql2 (>= 0.3.18, < 0.6.0)
omniauth
omniauth-facebook omniauth-facebook
omniauth-google-oauth2
puma (~> 3.0) puma (~> 3.0)
rails (~> 5.0.7, >= 5.0.7.2) rails (~> 5.0.7, >= 5.0.7.2)
sass-rails (~> 5.0) sass-rails (~> 5.0)
......
class TemplatesController < ApplicationController
before_action :set_template, only: [:show, :edit, :update, :destroy]
# GET /templates
# GET /templates.json
def index
@templates = Template.all
end
# GET /templates/1
# GET /templates/1.json
def show
end
# GET /templates/new
def new
@template = Template.new
end
# GET /templates/1/edit
def edit
end
# POST /templates
# POST /templates.json
def create
@template = Template.new(template_params)
respond_to do |format|
if @template.save
format.html { redirect_to @template, notice: 'Template was successfully created.' }
format.json { render :show, status: :created, location: @template }
else
format.html { render :new }
format.json { render json: @template.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /templates/1
# PATCH/PUT /templates/1.json
def update
respond_to do |format|
if @template.update(template_params)
format.html { redirect_to @template, notice: 'Template was successfully updated.' }
format.json { render :show, status: :ok, location: @template }
else
format.html { render :edit }
format.json { render json: @template.errors, status: :unprocessable_entity }
end
end
end
# DELETE /templates/1
# DELETE /templates/1.json
def destroy
@template.destroy
respond_to do |format|
format.html { redirect_to templates_url, notice: 'Template was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_template
@template = Template.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def template_params
params.require(:template).permit(:title, :desc)
end
end
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook def facebook
@user = User.from_omniauth(request.env["omniauth.auth"]) @user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted? if @user.persisted?
sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated sign_in_and_redirect @user, event: :authentication
set_flash_message(:notice, :success, kind: "Facebook") if is_navigational_format? set_flash_message(:notice, :success, kind: "Facebook") if is_navigational_format?
else else
session["devise.facebook_data"] = request.env["omniauth.auth"] session["devise.facebook_data"] = request.env["omniauth.auth"]
...@@ -12,6 +13,19 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController ...@@ -12,6 +13,19 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
end end
def failure def failure
redirect_to new_template_path redirect_to root_path
end
def google_oauth2
@user = User.from_omniauth(request.env['omniauth.auth'])
if @user.persisted?
flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'Google'
sign_in_and_redirect @user, event: :authentication
else
session['devise.google_data'] = request.env['omniauth.auth'].except(:extra)
redirect_to new_user_registration_url, alert: @user.errors.full_messages.join("\n")
end end
end
end end
\ No newline at end of file
class Template < ApplicationRecord
end
class User < ApplicationRecord class User < ApplicationRecord
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :omniauthable, omniauth_providers: [:facebook] :recoverable, :rememberable, :omniauthable,
omniauth_providers: [:facebook, :google_oauth2]
def self.new_with_session(params, session) def self.new_with_session(params, session)
...@@ -10,9 +11,9 @@ class User < ApplicationRecord ...@@ -10,9 +11,9 @@ class User < ApplicationRecord
user.email = data["email"] if user.email.blank? user.email = data["email"] if user.email.blank?
end end
end end
end end
def self.from_omniauth(auth) def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user| where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
# user.email = auth.info.email # user.email = auth.info.email
user.password = Devise.friendly_token[0,20] user.password = Devise.friendly_token[0,20]
...@@ -22,5 +23,19 @@ def self.from_omniauth(auth) ...@@ -22,5 +23,19 @@ def self.from_omniauth(auth)
# uncomment the line below to skip the confirmation emails. # uncomment the line below to skip the confirmation emails.
# user.skip_confirmation! # user.skip_confirmation!
end end
end end
def self.from_omniauth(access_token)
data = access_token.info
user = User.where(email: data['email']).first
# Uncomment the section below if you want users to be created if they don't exist
unless user
user = User.create(name: data['name'],
email: data['email'],
password: Devise.friendly_token[0,20]
)
end
user
end
end end
<% unless current_user %>
<%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path %>
<%= link_to "Sign in with Google", user_google_oauth2_omniauth_authorize_path %>
<% else %> <%= current_user[:name] %>
<%= link_to "Logout", destroy_user_session_path, method: :delete %>
<% end %>
<!DOCTYPE html>
<html>
<head>
<title>WarmCity</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= yield %>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>
<body>
<%= yield %>
</body>
</html>
<%= form_for(template) do |f| %>
<% if template.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(template.errors.count, "error") %> prohibited this template from being saved:</h2>
<ul>
<% template.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :desc %>
<%= f.text_area :desc %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
json.extract! template, :id, :title, :desc, :created_at, :updated_at
json.url template_url(template, format: :json)
<h1>Editing Template</h1>
<%= render 'form', template: @template %>
<%= link_to 'Show', @template %> |
<%= link_to 'Back', templates_path %>
<p id="notice"><%= notice %></p>
<h1>Templates</h1>
<table>
<thead>
<tr>
<th>Title</th>
<th>Desc</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @templates.each do |template| %>
<tr>
<td><%= template.title %></td>
<td><%= template.desc %></td>
<td><%= link_to 'Show', template %></td>
<td><%= link_to 'Edit', edit_template_path(template) %></td>
<td><%= link_to 'Destroy', template, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Template', new_template_path %>
<% unless current_user %> <%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path %><% else %> <%= current_user[:name] %> <%= link_to "Logout", destroy_user_session_path, method: :delete %><% end %>
<%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path %>
\ No newline at end of file
json.array! @templates, partial: "templates/template", as: :template
<h1>New Template</h1>
<%= render 'form', template: @template %>
<%= link_to 'Back', templates_path %>
<p id="notice"><%= notice %></p>
<p>
<strong>Title:</strong>
<%= @template.title %>
</p>
<p>
<strong>Desc:</strong>
<%= @template.desc %>
</p>
<%= link_to 'Edit', edit_template_path(@template) %> |
<%= link_to 'Back', templates_path %>
json.partial! "templates/template", template: @template
# frozen_string_literal: true
# Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
Devise.setup do |config| Devise.setup do |config|
# The secret key used by Devise. Devise uses this key to generate
# random tokens. Changing this key will render invalid all existing
# confirmation, reset password and unlock tokens in the database.
# Devise will use the `secret_key_base` as its `secret_key`
# by default. You can change it below and use your own secret key.
# config.secret_key = 'ed4b0fca8c5fb69dc0286b1bc45444ceadb0677c6696b0a9cf16a8600b19ffbe66d24672e3b3139caf775bb60d070d72f73819df6692bd815960577835eccb8f'
# ==> Controller configuration
# Configure the parent class to the devise controllers.
# config.parent_controller = 'DeviseController'
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class
# with default "from" parameter.
config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
# Configure the class responsible to send e-mails.
# config.mailer = 'Devise::Mailer'
# Configure the parent class responsible to send e-mails.
# config.parent_mailer = 'ActionMailer::Base'
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
# available as additional gems.
require 'devise/orm/active_record' require 'devise/orm/active_record'
# ==> Configuration for any authentication mechanism
# Configure which keys are used when authenticating a user. The default is
# just :email. You can configure it to use [:username, :subdomain], so for
# authenticating a user, both parameters are required. Remember that those
# parameters are used only when authenticating and not when retrieving from
# session. If you need permissions, you should implement that in a before filter.
# You can also supply a hash where the value is a boolean determining whether
# or not authentication should be aborted when the value is not present.
# config.authentication_keys = [:email]
# Configure parameters from the request object used for authentication. Each entry
# given should be a request method and it will automatically be passed to the
# find_for_authentication method and considered in your model lookup. For instance,
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
# The same considerations mentioned for authentication_keys also apply to request_keys.
# config.request_keys = []
# Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [:email] config.case_insensitive_keys = [:email]
# Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [:email] config.strip_whitespace_keys = [:email]
# Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the
# given strategies, for example, `config.params_authenticatable = [:database]` will
# enable it only for database (email + password) authentication.
# config.params_authenticatable = true
# Tell if authentication through HTTP Auth is enabled. False by default.
# It can be set to an array that will enable http authentication only for the
# given strategies, for example, `config.http_authenticatable = [:database]` will
# enable it only for database authentication. The supported strategies are:
# :database = Support basic authentication with authentication key + password
# config.http_authenticatable = false
# If 401 status code should be returned for AJAX requests. True by default.
# config.http_authenticatable_on_xhr = true
# The realm used in Http Basic Authentication. 'Application' by default.
# config.http_authentication_realm = 'Application'
# It will change confirmation, password recovery and other workflows
# to behave the same regardless if the e-mail provided was right or wrong.
# Does not affect registerable.
# config.paranoid = true
# By default Devise will store the user in session. You can skip storage for
# particular strategies by setting this option.
# Notice that if you are skipping storage for all authentication paths, you
# may want to disable generating routes to Devise's sessions controller by
# passing skip: :sessions to `devise_for` in your config/routes.rb
config.skip_session_storage = [:http_auth] config.skip_session_storage = [:http_auth]
# By default, Devise cleans up the CSRF token on authentication to
# avoid CSRF token fixation attacks. This means that, when using AJAX
# requests for sign in and sign up, you need to get a new CSRF token
# from the server. You can disable this option at your own risk.
# config.clean_up_csrf_token_on_authentication = true
# When false, Devise will not attempt to reload routes on eager load.
# This can reduce the time taken to boot the app but if your application
# requires the Devise mappings to be loaded during boot time the application
# won't boot properly.
# config.reload_routes = true
# ==> Configuration for :database_authenticatable
# For bcrypt, this is the cost for hashing the password and defaults to 11. If
# using other algorithms, it sets how many times you want the password to be hashed.
#
# Limiting the stretches to just one in testing will increase the performance of
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
# a value less than 10 in other environments. Note that, for bcrypt (the default
# algorithm), the cost increases exponentially with the number of stretches (e.g.
# a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
config.stretches = Rails.env.test? ? 1 : 11 config.stretches = Rails.env.test? ? 1 : 11
# Set up a pepper to generate the hashed password.
# config.pepper = '13b8e71660a1e4676df66a7457c7432c4b10b594b09e9823b33c138ce4565bb22e04212ffaf5c2a09c1115c8490c39ec591e5183212ba800731594a196c4d8d2'
# Send a notification to the original email when the user's email is changed.
# config.send_email_changed_notification = false
# Send a notification email when the user's password is changed.
# config.send_password_change_notification = false
# ==> Configuration for :confirmable
# A period that the user is allowed to access the website even without
# confirming their account. For instance, if set to 2.days, the user will be
# able to access the website for two days without confirming their account,
# access will be blocked just in the third day.
# You can also set it to nil, which will allow the user to access the website
# without confirming their account.
# Default is 0.days, meaning the user cannot access the website without
# confirming their account.
# config.allow_unconfirmed_access_for = 2.days
# A period that the user is allowed to confirm their account before their
# token becomes invalid. For example, if set to 3.days, the user can confirm
# their account within 3 days after the mail was sent, but on the fourth day
# their account can't be confirmed with the token any more.
# Default is nil, meaning there is no restriction on how long a user can take
# before confirming their account.
# config.confirm_within = 3.days
# If true, requires any email changes to be confirmed (exactly the same way as
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field (see migrations). Until confirmed, new email is stored in
# unconfirmed_email column, and copied to email column on successful confirmation.
config.reconfirmable = true config.reconfirmable = true
# Defines which key will be used when confirming an account
# config.confirmation_keys = [:email]
# ==> Configuration for :rememberable
# The time the user will be remembered without asking for credentials again.
# config.remember_for = 2.weeks
# Invalidates all the remember me tokens when the user signs out.
config.expire_all_remember_me_on_sign_out = true config.expire_all_remember_me_on_sign_out = true
# If true, extends the user's remember period when remembered via cookie.
# config.extend_remember_period = false
# Options to be passed to the created cookie. For instance, you can set
# secure: true in order to force SSL only cookies.
# config.rememberable_options = {}
# ==> Configuration for :validatable
# Range for password length.
config.password_length = 6..128 config.password_length = 6..128
# Email regex used to validate email formats. It simply asserts that
# one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity.
config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
# ==> Configuration for :timeoutable
# The time you want to timeout the user session without activity. After this
# time the user will be asked for credentials again. Default is 30 minutes.
# config.timeout_in = 30.minutes
# ==> Configuration for :lockable
# Defines which strategy will be used to lock an account.
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
# :none = No lock strategy. You should handle locking by yourself.
# config.lock_strategy = :failed_attempts
# Defines which key will be used when locking and unlocking an account
# config.unlock_keys = [:email]
# Defines which strategy will be used to unlock an account.
# :email = Sends an unlock link to the user email
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
# :both = Enables both strategies
# :none = No unlock strategy. You should handle unlocking by yourself.
# config.unlock_strategy = :both
# Number of authentication tries before locking an account if lock_strategy
# is failed attempts.
# config.maximum_attempts = 20
# Time interval to unlock the account if :time is enabled as unlock_strategy.
# config.unlock_in = 1.hour
# Warn on the last attempt before the account is locked.
# config.last_attempt_warning = true
# ==> Configuration for :recoverable
#
# Defines which key will be used when recovering the password for an account
# config.reset_password_keys = [:email]
# Time interval you can reset your password with a reset password key.
# Don't put a too small interval or your users won't have the time to
# change their passwords.
config.reset_password_within = 6.hours config.reset_password_within = 6.hours
# When set to false, does not sign a user in automatically after their password is config.sign_out_via = [:delete, :get]
# reset. Defaults to true, so a user is signed in automatically after a reset.
# config.sign_in_after_reset_password = true
# ==> Configuration for :encryptable
# Allow you to use another hashing or encryption algorithm besides bcrypt (default).
# You can use :sha1, :sha512 or algorithms from others authentication tools as
# :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
# for default behavior) and :restful_authentication_sha1 (then you should set
# stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
#
# Require the `devise-encryptable` gem when using anything other than bcrypt
# config.encryptor = :sha512
# ==> Scopes configuration
# Turn scoped views on. Before rendering "sessions/new", it will first check for
# "users/sessions/new". It's turned off by default because it's slower if you
# are using only default views.
# config.scoped_views = false
# Configure the default scope given to Warden. By default it's the first
# devise role declared in your routes (usually :user).
# config.default_scope = :user
# Set this configuration to false if you want /users/sign_out to sign out
# only the current scope. By default, Devise signs out all scopes.
# config.sign_out_all_scopes = true
# ==> Navigation configuration
# Lists the formats that should be treated as navigational. Formats like
# :html, should redirect to the sign in page when the user does not have
# access, but formats like :xml or :json, should return 401.
#
# If you have any extra navigational formats, like :iphone or :mobile, you
# should add them to the navigational formats lists.
#
# The "*/*" below is required to match Internet Explorer requests.
# config.navigational_formats = ['*/*', :html]
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete
# config.omniauth :facebook, ENV['FB_APP_ID'], ENV['FB_APP_SECRET'],
# scope: 'public_profile,email',
# info_fields: 'email,first_name,last_name,gender,birthday,location,picture',
# client_options: {
# site: 'https://graph.facebook.com/v2.11',
# authorize_url: "https://www.facebook.com/v2.11/dialog/oauth"
# }
config.omniauth :facebook, "2429624190692901", "03da24c1517b0bfa4acc70852f61fb60", config.omniauth :facebook, "2429624190692901", "03da24c1517b0bfa4acc70852f61fb60",
callback_url: "http://localhost:3000/users/auth/facebook/callback", callback_url: "http://localhost:3000/users/auth/facebook/callback",
...@@ -272,4 +32,7 @@ Devise.setup do |config| ...@@ -272,4 +32,7 @@ Devise.setup do |config|
site: 'https://graph.facebook.com/v2.11', site: 'https://graph.facebook.com/v2.11',
authorize_url: "https://www.facebook.com/v2.11/dialog/oauth" authorize_url: "https://www.facebook.com/v2.11/dialog/oauth"
} }
config.omniauth :google_oauth2, "444952886435-8s76oeuc53otc8q84jork9mq4php7e7t.apps.googleusercontent.com",
"vfJkP71fOkfDKVYa3RgXR3lW", {}
end end
Rails.application.routes.draw do Rails.application.routes.draw do
resources :templates root 'application#index'
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' } devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
end end
# Be sure to restart your server when you modify this file.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rails secret` to generate a secure secret key.
# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.
development: development:
secret_key_base: b1b8b2c8f26c31fb891d8f8eaf37f5bc26ea31ac8913a4acfe7e9013853eeb3df5e681187e8ed35df9e6526d9528973791f904727fe56d250d903ff21083ece6 secret_key_base: b1b8b2c8f26c31fb891d8f8eaf37f5bc26ea31ac8913a4acfe7e9013853eeb3df5e681187e8ed35df9e6526d9528973791f904727fe56d250d903ff21083ece6
GOOGLE_CLIENT_ID: 444952886435-8s76oeuc53otc8q84jork9mq4php7e7t.apps.googleusercontent.com
GOOGLE_SECRET_KEY: vfJkP71fOkfDKVYa3RgXR3lW
test: test:
secret_key_base: dd24cc39a6555956e85cb7d60612c685b91249ed8760a957b155ced0177eb172674137f73ba33d8b886f14089469703830d76ddbd42a996897d8b77aac43b33a secret_key_base: dd24cc39a6555956e85cb7d60612c685b91249ed8760a957b155ced0177eb172674137f73ba33d8b886f14089469703830d76ddbd42a996897d8b77aac43b33a
# Do not keep production secrets in the repository,
# instead read values from the environment.
production: production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
class CreateTemplates < ActiveRecord::Migration[5.0]
def change
create_table :templates do |t|
t.string :title
t.text :desc
t.timestamps
end
end
end
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20190829110429) do ActiveRecord::Schema.define(version: 20190829110429) do
create_table "templates", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "title"
t.text "desc", limit: 65535
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: "", null: false
......
require 'test_helper'
class TemplatesControllerTest < ActionDispatch::IntegrationTest
setup do
@template = templates(:one)
end
test "should get index" do
get templates_url
assert_response :success
end
test "should get new" do
get new_template_url
assert_response :success
end
test "should create template" do
assert_difference('Template.count') do
post templates_url, params: { template: { desc: @template.desc, title: @template.title } }
end
assert_redirected_to template_url(Template.last)
end
test "should show template" do
get template_url(@template)
assert_response :success
end
test "should get edit" do
get edit_template_url(@template)
assert_response :success
end
test "should update template" do
patch template_url(@template), params: { template: { desc: @template.desc, title: @template.title } }
assert_redirected_to template_url(@template)
end
test "should destroy template" do
assert_difference('Template.count', -1) do
delete template_url(@template)
end
assert_redirected_to templates_url
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
title: MyString
desc: MyText
two:
title: MyString
desc: MyText
require 'test_helper'
class TemplateTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Markdown is supported
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