You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

auth.txt 3.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. :mod:`auth` --- Authentication
  2. ==============================
  3. .. module:: auth
  4. :synopsis: Authentication module
  5. Authentication object
  6. ---------------------
  7. .. class:: Authentication(self, form, in_cookies, out_cookies, out)
  8. A new Authenticate object is created at the beginning of any request. It will manage login, session and
  9. cookies. :method:`update` must be called at the end of the request to update cookies and
  10. session.
  11. The constructor will also set the global `webnotes.conn`, `webnotes.session` and `webnotes.user`
  12. To enable a login, the :object:form must have a cmd = "login" (see request handling for more details)
  13. .. attribute:: conn
  14. `webnotes.db.Database` object created after authentication
  15. .. attribute:: session
  16. session dictionary of the current session
  17. .. attribute:: cookies
  18. session dictionary of incoming cookies
  19. .. attribute:: domain
  20. domain name of the request
  21. .. attribute:: remote_ip
  22. IP address of the reqeust
  23. .. method:: update()
  24. **Must be called at the end of the request, to update the session and clear expired sessions**
  25. .. method:: set_env()
  26. Sets the properties `domain` and `remote_ip` from the environmental variables
  27. .. method:: set_db()
  28. In case of a multi-database system, this methods sets the correct database connection.
  29. * It will first search for cookie `account_id`
  30. * It will next search for cookies or form variable `__account`
  31. * It will try and search from the domain mapping table `Account Domain` in the `accounts` database
  32. * It will try and use the default
  33. .. method:: check_ip()
  34. If the current request is from a separate IP than the one which was used to create the session, then
  35. this throws an Exception
  36. .. method:: load_session(sid)
  37. Load session from the given session id `sid`
  38. .. method:: login(as_guest = 0)
  39. Will login user from `self.form`. If as_guest is true, it will check if Guest profile is enabled
  40. It will also:
  41. * validate if approved ips are set in `Profile`
  42. * start the session
  43. * set "remember me"
  44. * return out.message as "Logged In"
  45. .. method:: check_password(user, pwd)
  46. Checks if the user has the pwd and is enabled
  47. .. method:: validate_ip(user)
  48. Validates IP address from the ip_address value in the user's `Profile`
  49. .. method:: start_session()
  50. Starts a session, and updates last login details in the users's `Profile`
  51. .. method:: clear_expired()
  52. Removes old sessions from `tabSessions` that are older than `session_expiry` in `Control Panel` or 24:00 hrs
  53. .. method:: set_cookies()
  54. Sets outgoing cookies
  55. .. method:: set_remember_me()
  56. Checks if there is a 'remember_me' property in `form` with a value and if true, its sets the
  57. expiry of each cookie for `remember_for_days` in `Control Panel` or 7 days
  58. .. method:: get_cookies()
  59. Loads incoming cookies in `cookies`