Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add github login #101

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

add github login #101

wants to merge 3 commits into from

Conversation

h1u2i3
Copy link
Contributor

@h1u2i3 h1u2i3 commented Apr 4, 2017

No description provided.

end

def authorize_url! do
OAuth2.Client.authorize_url!(client(), scope: "user,public_repo")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的权限要的太多了吧? 我试了一下,按你现在写的代码,应该用 user:email 就行了。 https://developer.github.com/v3/oauth/#scopes

OAuth2.Client.authorize_url!(client(), scope: "user,public_repo")
end

def get_token!(params \\ [], headers \\ [], opts \\ []) do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不太建议这里用这么多可选参数,使用起来选择太多,发而不太好用。而且你代码里其实也基本没用到什么默认参数的功能。可以把常用的参数作为必须的,比如 params。剩下的再考虑是可选吧

email && (user = Repo.get_by(User, email: email)) ->
{:ok, user}
email && name && Repo.get_by(User, name: name) ->
{:ok, insert_user(email, generate_name(name))}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里除了你这种做法(先根据 name 查 user),我想到还有一种做法是先直接插入数据,因为 name 有唯一索引,如果插入失败再生成 name 来创建,这样如果用户名不存在的话,就减少了查询。你觉得哪种好点?

@@ -39,6 +39,9 @@
<%= render @view_module, @view_template, assigns %>
</div>
<sidebar class="col-md-3" role="sidebar">
<%= if @user_id == nil do %>
<%= render ElixirChina.SharedView, "_social_login.html", conn: @conn %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我更倾向于把这个页面放在登录那里,不然到处都有这个登录按钮

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

额,确实有点简单粗暴了,还是放在登录界面里面好一点。

with {:ok, user} <- insert_user(email, name) do
{:ok, user}
else
{:error, %Ecto.Changeset{errors: [email: {"has already been taken", []}]}} ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里我倒觉得可以直接先按 email 来查,毕竟插入的操作不需要做很多,用户通过 GitHub 登录一次后,以后都可以通过 email 找到。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya. 再修改。

@DefiPanda DefiPanda force-pushed the master branch 8 times, most recently from 3b8344d to 4678982 Compare July 29, 2018 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants