Attempt to create custom login for Clojure / Korma / PostgreSQL site

I am completely stuck on where to start by registering the login area for the Clojure site that I am creating (for fun).

I looked at several resources that I will publish below, mercilessly copy / paste the code, and the closest I can get is one of two situations:

The login page accepts the login, but says that the login failed, although, as far as I can tell, the login is the same.

Or I get this error: There is no method in multimethod '-> sql' for the send value: null

I'm not sure how to interpret the above error: does it indicate that I need a multi-method or does it indicate that I need to check for null? Zero requirement makes no sense. I do not ask, but if someone wants to give an explanation, that's great.

I tested the result, comparing the results with the results for choosing from unprocessed non-hashed data, I looked at 5 variants of this topic, using everything from page-to-page calls to create new defpartials, methods, defn, etc.

Sources that I used (unfortunately, I can not list them all as the first time):

This one uses Clojure -> Korma -> PostgreSQL, but the code doesn't seem to work for multiple users?
http://www.vijaykiran.com/2012/01/17/web-application-development-with-clojure-part-2/

This shows how to use Noir and PostgreSQL (yes, I use Noir): https://yogthos.net:11794/blog/23-Noir+tutorial+-+part+2

4Clojure website, but it uses CongoMongo:

Clone of Heroku Twitter, but does not mention how to create logins for one person, and even more so several.

I also bought the Clojure Program from O'Reilly Press, but again, nothing about how to create a login area.

FIRST EDIT: I was asked to create a separate site github repository. This includes the Create Account workspace, which is located in the welcome.clj file and only the login area form in login.clj.

I tried to get some of the same errors that I had last night, and also try to get this working before I uploaded the files. At the moment, I have no reasonable starting points, so there is no implementation start yet. I am seriously confused by the solutions that I came up with, so I do not want to publish them. I understand what I have to do, but for some reason I cannot translate this. This is my first github account: my background is Python, Scheme a'la SICP, and some of the Python + PostgreSQL marketing programs I created.

SECOND EDITING: Ack! It seems that I can not make everything work ... Yes, I spent more than 20 minutes (hours) on it, so I only have to admit that I still do not have the necessary knowledge to achieve this, regardless of how many sources I am looking for. I transferred the updated files and all the extra stuff that I tried, including all the options in the login box to run raw SQL. The closest I can think of is to get it so that I don't have any errors, but there is no evidence that anyone has logged in. Thanks so much for the help and suggestions. I will certainly return to this later.

https://github.com/dt1/noirKormaLogin

+6
source share
1 answer

There are several problems that I see. First, in datapass.clj you create an object with no content. I'm not sure how Korma deals with this. It tries to output the results as contributions to other functions, so I could see how nil is entered there.

Secondly, you will need something to process the login message. (defpage ...) handles only GET requests. To process the message you will need a separate defpage . Something like that:

 (defpage [:post "/login"] {:keys [user-name pwd]} (if-let [user (db/find-user user)] (if (noir.util.crypt/compare pwd (:password user)) (do (noir.session/put! :some-key some-value) (noir.response/redirect "/success")) noir.response/redirect "/failed-to-login")) (noir.response/redirect "/failed-to-login")) 

session/put! is how you put data into the session. By default, in-memory storage is used. You will need to add Ring middleware to use persistent sessions (look at the session stores).

Also, with luck, someone just posted an authentication application for Noir ... you can see: https://github.com/xavi/noir-auth-app

+3
source

Source: https://habr.com/ru/post/923776/


All Articles