Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
  • This project
    • Loading...
  • Sign in / Register
S
sample_app
  • Overview
    • Overview
    • Details
    • Activity
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 0
    • Issues 0
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Đường Sỹ Hoàng
  • sample_app
  • Merge Requests
  • !8

Merged
Opened Nov 14, 2019 by Đường Sỹ Hoàng@hoangds 
  • Report abuse
Report abuse

Implement advanced login

×

Check out, review, and merge locally

Step 1. Fetch and check out the branch for this merge request

git fetch origin
git checkout -b advanced-login origin/advanced-login

Step 2. Review the changes locally

Step 3. Merge the branch and fix any conflicts that come up

git checkout master
git merge --no-ff advanced-login

Step 4. Push the result of the merge to GitLab

git push origin master

Note that pushing to GitLab requires write access to this repository.

Tip: You can also checkout merge requests locally by following these guidelines.

  • Discussion 14
  • Commits 7
  • Changes 12
{{ resolvedDiscussionCount }}/{{ discussionCount }} {{ resolvedCountText }} resolved
  • Đường Sỹ Hoàng @hoangds

    added 1 commit

    • 28743142 - Removed space

    Compare with previous version

    Nov 14, 2019

    added 1 commit

    • 28743142 - Removed space

    Compare with previous version

    added 1 commit * 28743142 - Removed space [Compare with previous version](https://gitlab.zigexn.vn/hoangds/sample_app/merge_requests/8/diffs?diff_id=4319&start_sha=79cf81685a64e8b9387acccfc6b248128cce769f)
    Toggle commit list
  • Son Do Hong
    @sondh started a discussion on the diff Nov 14, 2019
    Resolved by Son Do Hong Nov 14, 2019
    app/helpers/sessions_helper.rb
    5 5 end
    6
    7 # Returns the current logged-in user (if any)
    6
    7 # Remembers a user in a persistent session.
    8 def remember(user)
    9 user.remember
    10 cookies.permanent.signed[:user_id] = user.id
    11 cookies.permanent[:remember_token] = user.remember_token
    12 end
    13
    14 # Returns the user corresponding to the remember token cookie.
    8 15 def current_user
    9 if session[:user_id]
    10 @current_user ||= User.find_by(id: session[:user_id])
    16 if (user_id = session[:user_id])
    • Son Do Hong @sondh commented Nov 14, 2019
      Master

      đọc kĩ lại đoạn này trong sách

      đọc kĩ lại đoạn này trong sách
    • Son Do Hong @sondh commented Nov 14, 2019
      Master

      dấu = và dấu == khác gì nhau?

      dấu `=` và dấu `==` khác gì nhau?
    • Đường Sỹ Hoàng @hoangds commented Nov 14, 2019
      Master

      Dấu = là chỉ phép toán tử gán giá trị.Còn dấu == chỉ phép toán so sánh bằng nhau giữa 2 giá trị.

      Dấu `=` là chỉ phép toán tử gán giá trị.Còn dấu `==` chỉ phép toán so sánh bằng nhau giữa 2 giá trị.
    • Son Do Hong @sondh commented Nov 14, 2019
      Master

      vậy trong câu phía trên, khi nào thì đoạn code trong block else sẽ đc thực hiện?

      vậy trong câu phía trên, khi nào thì đoạn code trong block `else` sẽ đc thực hiện?
    • Đường Sỹ Hoàng @hoangds commented Nov 14, 2019
      Master

      Đoạn code trong block elsexảy ra khi điều kiện user_id = session[:user_id] không xảy ra, tức là khi session user id không tồn tại.

      Edited Nov 14, 2019 by Đường Sỹ Hoàng
      Đoạn code trong block `else`xảy ra khi điều kiện `user_id = session[:user_id]` không xảy ra, tức là khi session user id không tồn tại.
    • Son Do Hong @sondh commented Nov 14, 2019
      Master

      vậy khi nào đoạn code trong if được thực hiện?

      vậy khi nào đoạn code trong `if` được thực hiện?
    Please register or sign in to reply
  • Đường Sỹ Hoàng @hoangds

    added 1 commit

    • d86eafca - Removed space

    Compare with previous version

    Nov 14, 2019

    added 1 commit

    • d86eafca - Removed space

    Compare with previous version

    added 1 commit * d86eafca - Removed space [Compare with previous version](https://gitlab.zigexn.vn/hoangds/sample_app/merge_requests/8/diffs?diff_id=4320&start_sha=2874314217d05e714f104bc2b58296f8b9954100)
    Toggle commit list
  • Van Hau Le
    @haulv started a discussion on the diff Nov 14, 2019
    app/models/user.rb
    9 11
    10 12 has_secure_password
    11 13
    12 def User.digest(string)
    13 cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
    14 BCrypt::Password.create(string, cost: cost)
    15 end
    14 # Returns the hash digest of the given string.
    15 def User.digest(string)
    16 cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
    17 BCrypt::Password.create(string, cost: cost)
    18 end
    19
    • Van Hau Le @haulv commented Nov 14, 2019
      Developer

      @hoangds should change def class method use self keyword instead of class name

      @hoangds should change `def class method` use `self` keyword instead of `class name`
    Please register or sign in to reply
  • Son Do Hong
    @sondh started a discussion on an old version of the diff Nov 14, 2019
    Resolved by Đường Sỹ Hoàng Nov 14, 2019
    app/helpers/sessions_helper.rb
    6
    7 # Remembers a user in a persistent session.
    8 def remember(user)
    9 user.remember
    10 cookies.permanent.signed[:user_id] = user.id
    11 cookies.permanent[:remember_token] = user.remember_token
    12 end
    13
    14 # Returns the user corresponding to the remember token cookie.
    8 15 def current_user
    9 if session[:user_id]
    10 @current_user ||= User.find_by(id: session[:user_id])
    16 if (user_id = session[:user_id])
    17 @current_user ||= User.find_by(id: user_id)
    18 elsif (user_id = cookies.signed[:user_id])
    19 #raise # The tests still pass, so this branch is currently untested.
    • Son Do Hong @sondh commented Nov 14, 2019
      Master

      remove this comment

      remove this comment
    • Đường Sỹ Hoàng @hoangds

      changed this line in version 4 of the diff

      Nov 14, 2019

      changed this line in version 4 of the diff

      changed this line in [version 4 of the diff](https://gitlab.zigexn.vn/hoangds/sample_app/merge_requests/8/diffs?diff_id=4322&start_sha=d86eafcad5c7be11f2cd5b7970d0b67863f16b39#59459d8ae6eb34ed02b9dd3b6d40207e2ab982ca_19_19)
      Toggle commit list
    Please register or sign in to reply
  • Son Do Hong
    @sondh started a discussion on an old version of the diff Nov 14, 2019
    Last updated by Đường Sỹ Hoàng Nov 14, 2019
    test/models/user_test.rb
    63 62 end
    64 63
    65 64 test "password should be present (nonblank)" do
    66 @user.password = @user.password_confirmation = " " * 6
    65 @user.password = @user.password_confirmation = "" * 6
    • Son Do Hong @sondh commented Nov 14, 2019
      Master

      sao lại thay đổi test case vậy em

      sao lại thay đổi test case vậy em
    • Đường Sỹ Hoàng @hoangds

      changed this line in version 5 of the diff

      Nov 14, 2019

      changed this line in version 5 of the diff

      changed this line in [version 5 of the diff](https://gitlab.zigexn.vn/hoangds/sample_app/merge_requests/8/diffs?diff_id=4324&start_sha=df04959365457b6a96a307767652b61dc0b91faa#b2c42539e98b59c86729767abb84b6b86ef5d6b0_65_65)
      Toggle commit list
    Please register or sign in to reply
  • Đường Sỹ Hoàng @hoangds

    added 1 commit

    • df049593 - Removed comment

    Compare with previous version

    Nov 14, 2019

    added 1 commit

    • df049593 - Removed comment

    Compare with previous version

    added 1 commit * df049593 - Removed comment [Compare with previous version](https://gitlab.zigexn.vn/hoangds/sample_app/merge_requests/8/diffs?diff_id=4322&start_sha=d86eafcad5c7be11f2cd5b7970d0b67863f16b39)
    Toggle commit list
  • Son Do Hong
    @sondh started a discussion on the diff Nov 14, 2019
    Resolved by Son Do Hong Nov 14, 2019
    app/models/user.rb
    1 1 class User < ApplicationRecord
    2 2 VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
    3 3
    4 attr_accessor :remember_token
    • Son Do Hong @sondh commented Nov 14, 2019
      Master

      ý nghĩa của attr_accessor là gì

      ý nghĩa của `attr_accessor` là gì
    • Đường Sỹ Hoàng @hoangds commented Nov 14, 2019
      Master

      ý nghĩa của attr_accessor là tạo ra thuộc tính có thể truy được tương ứng trong đoạn code này là :remember_token.Nó cũng tạo ra 2 phương thức Get(cho phép người code lấy ra thuộc tính và Set(gán cho nó giá trị).

      Edited Nov 14, 2019
      ý nghĩa của `attr_accessor` là tạo ra thuộc tính có thể truy được tương ứng trong đoạn code này là `:remember_token`.Nó cũng tạo ra 2 phương thức Get(cho phép người code lấy ra thuộc tính và Set(gán cho nó giá trị).
    Please register or sign in to reply
  • Đường Sỹ Hoàng @hoangds

    added 1 commit

    • 1607711b - Removed space

    Compare with previous version

    Nov 14, 2019

    added 1 commit

    • 1607711b - Removed space

    Compare with previous version

    added 1 commit * 1607711b - Removed space [Compare with previous version](https://gitlab.zigexn.vn/hoangds/sample_app/merge_requests/8/diffs?diff_id=4324&start_sha=df04959365457b6a96a307767652b61dc0b91faa)
    Toggle commit list
  • Son Do Hong
    @sondh started a discussion on an old version of the diff Nov 14, 2019
    Last updated by Đường Sỹ Hoàng Nov 14, 2019
    app/models/user.rb
    14 class << self
    15 # Returns the hash digest of the given string.
    16 def digest(string)
    17 cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
    18 BCrypt::Password.create(string, cost: cost)
    19 end
    20
    21 # Returns a random token.
    22 def new_token
    23 SecureRandom.urlsafe_base64
    24 end
    15 25 end
    26
    27 # Remembers a user in the database for use in persistent sessions
    28 def remember
    29 self.remember_token = User.new_token
    • Son Do Hong @sondh commented Nov 14, 2019
      Master

      Trong class nên gọi là self.class.new_token thay vì gọi tên class User.new_token

      Edited Nov 14, 2019 by Son Do Hong
      Trong class nên gọi là `self.class.new_token` thay vì gọi tên class `User.new_token`
    • Đường Sỹ Hoàng @hoangds

      changed this line in version 6 of the diff

      Nov 14, 2019

      changed this line in version 6 of the diff

      changed this line in [version 6 of the diff](https://gitlab.zigexn.vn/hoangds/sample_app/merge_requests/8/diffs?diff_id=4325&start_sha=1607711b2dd102d1ee25c2dc0247913d9dbd5966#4ed0c03b53dbc8320da88e7887465514cd9e90a4_29_29)
      Toggle commit list
    Please register or sign in to reply
  • Son Do Hong
    @sondh started a discussion on an old version of the diff Nov 14, 2019
    Last updated by Đường Sỹ Hoàng Nov 14, 2019
    app/models/user.rb
    15 # Returns the hash digest of the given string.
    16 def digest(string)
    17 cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
    18 BCrypt::Password.create(string, cost: cost)
    19 end
    20
    21 # Returns a random token.
    22 def new_token
    23 SecureRandom.urlsafe_base64
    24 end
    15 25 end
    26
    27 # Remembers a user in the database for use in persistent sessions
    28 def remember
    29 self.remember_token = User.new_token
    30 update_attribute(:remember_digest, User.digest(remember_token))
    • Son Do Hong @sondh commented Nov 14, 2019
      Master

      tương tự comment trên

      tương tự comment trên
    • Đường Sỹ Hoàng @hoangds

      changed this line in version 6 of the diff

      Nov 14, 2019

      changed this line in version 6 of the diff

      changed this line in [version 6 of the diff](https://gitlab.zigexn.vn/hoangds/sample_app/merge_requests/8/diffs?diff_id=4325&start_sha=1607711b2dd102d1ee25c2dc0247913d9dbd5966#4ed0c03b53dbc8320da88e7887465514cd9e90a4_30_29)
      Toggle commit list
    Please register or sign in to reply
  • Đường Sỹ Hoàng @hoangds

    added 1 commit

    • 62e0066e - Replaced User with self class

    Compare with previous version

    Nov 14, 2019

    added 1 commit

    • 62e0066e - Replaced User with self class

    Compare with previous version

    added 1 commit * 62e0066e - Replaced User with self class [Compare with previous version](https://gitlab.zigexn.vn/hoangds/sample_app/merge_requests/8/diffs?diff_id=4325&start_sha=1607711b2dd102d1ee25c2dc0247913d9dbd5966)
    Toggle commit list
  • Son Do Hong
    @sondh started a discussion on an old version of the diff Nov 14, 2019
    Last updated by Đường Sỹ Hoàng Nov 14, 2019
    app/models/user.rb
    16 def digest(string)
    17 cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
    18 BCrypt::Password.create(string, cost: cost)
    19 end
    20
    21 # Returns a random token.
    22 def new_token
    23 SecureRandom.urlsafe_base64
    24 end
    15 25 end
    26
    27 # Remembers a user in the database for use in persistent sessions
    28 def remember
    29 self.remember_token = self.class.new_token
    30 update_attribute(:remember_digest, self.class.digest(remember_token))
    31 #BCrypt::Password.new(remember_digest).is_password?(remember_token)
    • Son Do Hong @sondh commented Nov 14, 2019
      Master

      remove comment

      remove comment
    • Đường Sỹ Hoàng @hoangds

      changed this line in version 7 of the diff

      Nov 14, 2019

      changed this line in version 7 of the diff

      changed this line in [version 7 of the diff](https://gitlab.zigexn.vn/hoangds/sample_app/merge_requests/8/diffs?diff_id=4326&start_sha=62e0066e28304a0c47c3a6dd6334d8301535465b#4ed0c03b53dbc8320da88e7887465514cd9e90a4_31_28)
      Toggle commit list
    Please register or sign in to reply
  • Đường Sỹ Hoàng @hoangds

    added 1 commit

    • bd88c704 - Fixed identation

    Compare with previous version

    Nov 14, 2019

    added 1 commit

    • bd88c704 - Fixed identation

    Compare with previous version

    added 1 commit * bd88c704 - Fixed identation [Compare with previous version](https://gitlab.zigexn.vn/hoangds/sample_app/merge_requests/8/diffs?diff_id=4326&start_sha=62e0066e28304a0c47c3a6dd6334d8301535465b)
    Toggle commit list
  • Son Do Hong @sondh

    mentioned in commit 9c88ae2a

    Nov 14, 2019

    mentioned in commit 9c88ae2a

    mentioned in commit 9c88ae2a9d3db73e99103d0b0fd1c63b843ee723
    Toggle commit list
  • Son Do Hong @sondh

    merged

    Nov 14, 2019

    merged

    merged
    Toggle commit list
  • Write
  • Preview
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 sign in to comment
Son Do Hong
Assignee
Son Do Hong @sondh
Assign to
None
Milestone
None
Assign milestone
Time tracking
3
3 participants
Reference: hoangds/sample_app!8
×

Revert this merge request

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.
×

Cherry-pick this merge request

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.