Last active
September 10, 2016 15:34
-
-
Save adammiribyan/025b6dc4529efb2ff527c033cf427617 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| create_table :students do |t| | |
| t.string :first_name | |
| t.string :last_name | |
| t.string :citizenship | |
| t.string :rodne_cislo | |
| t.string :group | |
| t.date :date_of_birth | |
| t.string :studies_state | |
| t.string :primary_specialty | |
| t.string :secondary_specialty | |
| t.string :foreign_language | |
| ... | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| create_table :users do |t| | |
| ## Database authenticatable | |
| t.string :email, null: false, default: "" | |
| t.string :encrypted_password, null: false, default: "" | |
| ## Recoverable | |
| t.string :reset_password_token | |
| t.datetime :reset_password_sent_at | |
| ## Rememberable | |
| t.datetime :remember_created_at | |
| ## Trackable | |
| t.integer :sign_in_count, default: 0, null: false | |
| t.datetime :current_sign_in_at | |
| t.datetime :last_sign_in_at | |
| t.inet :current_sign_in_ip | |
| t.inet :last_sign_in_ip | |
| t.timestamps null: false | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| create_table :imports do |t| | |
| t.integer :creator_id | |
| t.string :source | |
| t.string :status | |
| t.timestamps | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| create_table :exports do |t| | |
| t.integer :creator_id | |
| t.string :result | |
| t.timestamps | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <% title @user.email %> | |
| <%= page_header 'Editovat uživatele' %> | |
| <div class="panel panel-defult"> | |
| <div class="panel-body"> | |
| <%= form_for @user do |f| %> | |
| <div class="form-group"> | |
| <%= label_tag 'Email' %> | |
| <%= f.email_field :email, class: 'form-control' %> | |
| </div> | |
| <div class="form-group"> | |
| <%= label_tag 'Heslo' %> | |
| <%= f.password_field :password, class: 'form-control' %> | |
| </div> | |
| <div class="form-group"> | |
| <%= label_tag 'Potvrzení hesla' %> | |
| <%= f.password_field :password_confirmation, class: 'form-control' %> | |
| </div> | |
| <button type="submit" class="btn btn-primary">Uložit</button> | |
| <% end %> | |
| </div> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Encryptable | |
| def encrypt_columns(*columns) | |
| columns.each do |column| | |
| if self.column_names.include?(column.to_s) | |
| define_method "#{column}=" do |value| | |
| self[column] = self.class.crypt.encrypt_and_sign(value) | |
| end | |
| define_method "#{column}" do | |
| self.class.crypt.decrypt_and_verify(self[column]) | |
| end | |
| end | |
| end | |
| end | |
| def crypt | |
| salt = ENV['crypt_salt'] | |
| key = ActiveSupport::KeyGenerator.new('password').generate_key(salt) | |
| @crypt ||= ActiveSupport::MessageEncryptor.new(key) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Student < ApplicationRecord | |
| encrypt_columns :first_name, :last_name, :rodne_cislo | |
| ... | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UsersController < ApplicationController | |
| before_action :authenticate_user!, only: [:index] | |
| before_action :set_user, except: [:index] | |
| def index | |
| @users = User.all | |
| end | |
| def edit | |
| end | |
| def update | |
| @user.update_attributes(user_params) | |
| redirect_to users_path | |
| end | |
| def destroy | |
| @user.destroy | |
| redirect_to users_path | |
| end | |
| private | |
| def set_user | |
| @user = User.find(params[:id]) | |
| end | |
| def user_params | |
| params.require(:user).permit(:email, :password, :password_confirmation) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment