Comments (8)
I've just updated to version 0.12, and this version contains the ability to use a custom database call to Openmaize.Login.
The new module Openmaize.LoginTools show an example of how to define the function to query the database.
What you need to do is define your own query function (with 3 arguments) and then call it when using Openmaize.Login, like this (imagining your function is called Tools.query_func):
plug Openmaize.Login, [database_call: &Tools.query_func/3] when action in [:login_user]
Let me know if you have any questions / problems.
from openmaize.
Thats awesome, but I'm still a little fuzzy on how to use it. Would I just create my own module with the query to get the user and then pipe it back to the check_password function to continue the process? For instance:
plug Openmaize.Login, [database_call: &Database.find_user/3] when action in [:login_user]
def module Database do
alias Openmaize.Login
blah blah
def find_user do
{query}
|> check_password
What three parameters is the find_user/3 function expecting? Thank you for the help!
from openmaize.
If you're using :name to identify the user in the database, find_user expects :name and "name" as the first two arguments (if you're using :email, they would be :email and "email"). The third argument will be the following map - %{"name" => name, "password" => password}
Your Database module would be something like:
defmodule Database do
alias Openmaize.LoginTools
def find_user(:name, "name", user_params) do
%{"name" => name, "password" => password} = user_params
rethink_query_func(name) # this needs to return a user model
|> LoginTools.check_pass(password)
end
end
And then in your controller file:
plug Openmaize.Login, [database_call: &Database.find_user/3] when action in [:login_user]
Let me know if you have any further questions.
from openmaize.
So, I got it set up, but I am receiving an error when trying to log in. It is saying:
no function clause matching in Userquery.find_user/3
Here is the output from the console:
lib/App/userquery.ex:7: Userquery.find_user(:name, "name", %{"password" => "pass", "username" => "bob"})
I have this in my page_controller:
plug Openmaize.Login, [database_call: &Userquery.find_user/3] when action in [:login_user]
Here is my Userquery module:
defmodule Userquery do
alias Openmaize.LoginTools
import RethinkDB.Query
def find_user(:username, "username", user_params) do
%{"username" => username, "password" => password} = user_params
Query.table("users")
|> Query.filter(%{username: username}) # this needs to return a user model
|> LoginTools.check_pass(password)
end
end
from openmaize.
In the |> Query.filter(%{username: username})
line, could you add |> IO.inspect
to it (instead of the comment), and let me know what the output is?
If you could me any other info about the error, that would be really helpful.
from openmaize.
Thanks for all the help. Another question:
The path for a user's profile is /profiles/show/:id, so how can I redirect to this upon login and /profiles/new upon registration? I know there are redirects in the openmaize config, but this goes beyond the examples. Thanks
from openmaize.
Ok, it will help people searching these issues if we close this one first. Then you can open a new issue about the redirects. Please give me a little more information about what you want to achieve.
from openmaize.
In the latest version in the master branch (and for versioin 0.13), I've changed this function to just cover the query, and I've changed the name of the option from database_call
to query_function
. The query_tools file will give you some idea of how it should now be written.
Your custom function needs to be called with two arguments - in your case it will be the username as the first argument and :username
as the second argument. It then needs to return the user model (you don't have to include the check_pass call).
Sorry about making you change your code, but I think it makes more sense to restrict this function to just the query.
Let me know if you have any questions.
from openmaize.
Related Issues (20)
- How to translate short password validation? HOT 1
- add_confirm_token is missing on develop HOT 4
- Is this going to be deprecated? HOT 1
- Newbie question: How would you proceed on verifying the confirmation link? HOT 1
- Move mix phoenixauth generator to a separate installer, out of the hex package HOT 1
- Installer cannot find templates HOT 4
- Facebook, Twitter, ect... Oauth into Openmaize? HOT 3
- Add logging to login and email confirmation modules HOT 3
- Installer Generates API template for HTML site. HOT 2
- Remove the unique_id argument for the installer HOT 1
- Prevent sensitive information being sent on from Openmaize modules
- Installer not working HOT 2
- Password reset can't handle non existing email address HOT 4
- Provide two-factor authentication workflow guide HOT 2
- Support for Phoenix 1.3.0 file and directory structure conventions HOT 7
- Move repo and user_model values to the config HOT 3
- Disable confirmation HOT 2
- create both api auth for api's & session auth for html site HOT 7
- Remove hash_name and crypto_mod config values
- Spring cleaning / reorganization -- discussion HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openmaize.