Git Product home page Git Product logo

play_auth's Introduction

PlayAuth

这个 gem 目前用作简单的用户验证管理,在组件开发中替代厚重的devise 方便团队进行组件开发

组件开发规范参考:
http://s.4ye.me/DE1J85

使用办法

在sample的 Gemfile 中添加引用

# file ./Gemfile
gem 'play_auth', :github => 'mindpin/play_auth',
                 :tag => :latest

然后运行

bundle install

使用示例

codestart,生成的项目,可以看出最基本的使用形式:

.engine-generated
  .desc 
    %span rails engine 
    %strong second_gem 
    %span 已成功创建
  .desc 你可以继续进行组件开发了

.engine-generated
  - if user_signed_in?
    .desc.current-user
      %span 当前用户:
      %strong= current_user.name
  - else
    .desc
      %span 当前无登录用户

  .desc
    %span 访问
    %a{:href => '/auth'} /auth
    %span 注册
  .desc
    %span 访问
    %a{:href => '/auth/login'} /auth/login
    %span 登录
  .desc
    %span 点击
    %a{:href => '/auth/logout', :data => {:method => :delete}} DELETE /auth/logout
    %span 登出

主要方法为:

current_user

获取当前登录用户,未登录返回nil

user_signed_in?

是否已经登录

sign_in(scope, user)

使用user登录,scope为devise才用到,不熟悉的,这里传入 :user 即可

sign_out(resource_or_scope=nil)

登出,传入参数为仿devise设计,不熟悉的,这里可以忽略

play_auth's People

Contributors

blackdust avatar destinyd avatar fushang318 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

blackdust

play_auth's Issues

优化建议:增加一个初始化一些用户数据的 rake 任务

开发中每次都要注册,而且有时候会忘记自己注册过的账号用户名和密码
可以做以下两件事情,解决这个痛点

  1. 增加一个 rake 任务,可以初始化一些用来开发的用户(统一的用户登录密码,方便登录),包括 用户名 用户邮箱 用户头像
  2. 增加一个页面可以查看系统中已经有的所有用户,点击某个用户可以直接用该用户登录

User关联定义方式

由于User经常需要has_many关联其他model
本人尝试通过 config/initializers/xx.rb 的形式去定义

User.has_many :joins, class_name: 'KcCourses::Join'

一段时间后会失效


正确的定义方式(宋亮提供):

通过在engine里直接定义

# lib/xxx/engine.rb
module BankTrain
  class Engine < ::Rails::Engine
    isolate_namespace BankTrain
    config.to_prepare do
      ApplicationController.helper ::ApplicationHelper

      User.class_eval do
        include BankTrain::Post::UserMethods
      end
    end
    config.i18n.default_locale = "zh-CN"
  end
end
# app/models/post.rb
module BankTrain
  class Post
    module UserMethods
      extend ActiveSupport::Concern
      included do
        has_and_belongs_to_many :train_posts, class_name: 'BankTrain::Post'
      end
    end
  end
end

有一些像 bucketerize 这种模型是后设定的

sample 里可以通过如下方式定义

# sample/config/initializers/gem_integration.rb
User.class_eval do
  has_many :folders
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.