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.

1307 lines
39 KiB

Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package user
  6. import (
  7. "errors"
  8. "fmt"
  9. "net/http"
  10. "strings"
  11. "code.gitea.io/gitea/models"
  12. "code.gitea.io/gitea/modules/auth"
  13. "code.gitea.io/gitea/modules/auth/oauth2"
  14. "code.gitea.io/gitea/modules/base"
  15. "code.gitea.io/gitea/modules/context"
  16. "code.gitea.io/gitea/modules/log"
  17. "code.gitea.io/gitea/modules/recaptcha"
  18. "code.gitea.io/gitea/modules/setting"
  19. "code.gitea.io/gitea/modules/util"
  20. "github.com/go-macaron/captcha"
  21. "github.com/markbates/goth"
  22. "github.com/tstranex/u2f"
  23. )
  24. const (
  25. // tplMustChangePassword template for updating a user's password
  26. tplMustChangePassword = "user/auth/change_passwd"
  27. // tplSignIn template for sign in page
  28. tplSignIn base.TplName = "user/auth/signin"
  29. // tplSignUp template path for sign up page
  30. tplSignUp base.TplName = "user/auth/signup"
  31. // TplActivate template path for activate user
  32. TplActivate base.TplName = "user/auth/activate"
  33. tplForgotPassword base.TplName = "user/auth/forgot_passwd"
  34. tplResetPassword base.TplName = "user/auth/reset_passwd"
  35. tplTwofa base.TplName = "user/auth/twofa"
  36. tplTwofaScratch base.TplName = "user/auth/twofa_scratch"
  37. tplLinkAccount base.TplName = "user/auth/link_account"
  38. tplU2F base.TplName = "user/auth/u2f"
  39. )
  40. // AutoSignIn reads cookie and try to auto-login.
  41. func AutoSignIn(ctx *context.Context) (bool, error) {
  42. if !models.HasEngine {
  43. return false, nil
  44. }
  45. uname := ctx.GetCookie(setting.CookieUserName)
  46. if len(uname) == 0 {
  47. return false, nil
  48. }
  49. isSucceed := false
  50. defer func() {
  51. if !isSucceed {
  52. log.Trace("auto-login cookie cleared: %s", uname)
  53. ctx.SetCookie(setting.CookieUserName, "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  54. ctx.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  55. }
  56. }()
  57. u, err := models.GetUserByName(uname)
  58. if err != nil {
  59. if !models.IsErrUserNotExist(err) {
  60. return false, fmt.Errorf("GetUserByName: %v", err)
  61. }
  62. return false, nil
  63. }
  64. if val, _ := ctx.GetSuperSecureCookie(
  65. base.EncodeMD5(u.Rands+u.Passwd), setting.CookieRememberName); val != u.Name {
  66. return false, nil
  67. }
  68. isSucceed = true
  69. ctx.Session.Set("uid", u.ID)
  70. ctx.Session.Set("uname", u.Name)
  71. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  72. return true, nil
  73. }
  74. func checkAutoLogin(ctx *context.Context) bool {
  75. // Check auto-login.
  76. isSucceed, err := AutoSignIn(ctx)
  77. if err != nil {
  78. ctx.ServerError("AutoSignIn", err)
  79. return true
  80. }
  81. redirectTo := ctx.Query("redirect_to")
  82. if len(redirectTo) > 0 {
  83. ctx.SetCookie("redirect_to", redirectTo, 0, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  84. } else {
  85. redirectTo = ctx.GetCookie("redirect_to")
  86. }
  87. if isSucceed {
  88. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  89. ctx.RedirectToFirst(redirectTo, setting.AppSubURL+string(setting.LandingPageURL))
  90. return true
  91. }
  92. return false
  93. }
  94. // SignIn render sign in page
  95. func SignIn(ctx *context.Context) {
  96. ctx.Data["Title"] = ctx.Tr("sign_in")
  97. // Check auto-login.
  98. if checkAutoLogin(ctx) {
  99. return
  100. }
  101. orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers()
  102. if err != nil {
  103. ctx.ServerError("UserSignIn", err)
  104. return
  105. }
  106. ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names
  107. ctx.Data["OAuth2Providers"] = oauth2Providers
  108. ctx.Data["Title"] = ctx.Tr("sign_in")
  109. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login"
  110. ctx.Data["PageIsSignIn"] = true
  111. ctx.Data["PageIsLogin"] = true
  112. ctx.HTML(200, tplSignIn)
  113. }
  114. // SignInPost response for sign in request
  115. func SignInPost(ctx *context.Context, form auth.SignInForm) {
  116. ctx.Data["Title"] = ctx.Tr("sign_in")
  117. orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers()
  118. if err != nil {
  119. ctx.ServerError("UserSignIn", err)
  120. return
  121. }
  122. ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names
  123. ctx.Data["OAuth2Providers"] = oauth2Providers
  124. ctx.Data["Title"] = ctx.Tr("sign_in")
  125. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login"
  126. ctx.Data["PageIsSignIn"] = true
  127. ctx.Data["PageIsLogin"] = true
  128. if ctx.HasError() {
  129. ctx.HTML(200, tplSignIn)
  130. return
  131. }
  132. u, err := models.UserSignIn(form.UserName, form.Password)
  133. if err != nil {
  134. if models.IsErrUserNotExist(err) {
  135. ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form)
  136. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  137. } else if models.IsErrEmailAlreadyUsed(err) {
  138. ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignIn, &form)
  139. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  140. } else if models.IsErrUserProhibitLogin(err) {
  141. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  142. ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
  143. ctx.HTML(200, "user/auth/prohibit_login")
  144. } else if models.IsErrUserInactive(err) {
  145. if setting.Service.RegisterEmailConfirm {
  146. ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
  147. ctx.HTML(200, TplActivate)
  148. } else {
  149. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  150. ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
  151. ctx.HTML(200, "user/auth/prohibit_login")
  152. }
  153. } else {
  154. ctx.ServerError("UserSignIn", err)
  155. }
  156. return
  157. }
  158. // If this user is enrolled in 2FA, we can't sign the user in just yet.
  159. // Instead, redirect them to the 2FA authentication page.
  160. _, err = models.GetTwoFactorByUID(u.ID)
  161. if err != nil {
  162. if models.IsErrTwoFactorNotEnrolled(err) {
  163. handleSignIn(ctx, u, form.Remember)
  164. } else {
  165. ctx.ServerError("UserSignIn", err)
  166. }
  167. return
  168. }
  169. // User needs to use 2FA, save data and redirect to 2FA page.
  170. ctx.Session.Set("twofaUid", u.ID)
  171. ctx.Session.Set("twofaRemember", form.Remember)
  172. regs, err := models.GetU2FRegistrationsByUID(u.ID)
  173. if err == nil && len(regs) > 0 {
  174. ctx.Redirect(setting.AppSubURL + "/user/u2f")
  175. return
  176. }
  177. ctx.Redirect(setting.AppSubURL + "/user/two_factor")
  178. }
  179. // TwoFactor shows the user a two-factor authentication page.
  180. func TwoFactor(ctx *context.Context) {
  181. ctx.Data["Title"] = ctx.Tr("twofa")
  182. // Check auto-login.
  183. if checkAutoLogin(ctx) {
  184. return
  185. }
  186. // Ensure user is in a 2FA session.
  187. if ctx.Session.Get("twofaUid") == nil {
  188. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  189. return
  190. }
  191. ctx.HTML(200, tplTwofa)
  192. }
  193. // TwoFactorPost validates a user's two-factor authentication token.
  194. func TwoFactorPost(ctx *context.Context, form auth.TwoFactorAuthForm) {
  195. ctx.Data["Title"] = ctx.Tr("twofa")
  196. // Ensure user is in a 2FA session.
  197. idSess := ctx.Session.Get("twofaUid")
  198. if idSess == nil {
  199. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  200. return
  201. }
  202. id := idSess.(int64)
  203. twofa, err := models.GetTwoFactorByUID(id)
  204. if err != nil {
  205. ctx.ServerError("UserSignIn", err)
  206. return
  207. }
  208. // Validate the passcode with the stored TOTP secret.
  209. ok, err := twofa.ValidateTOTP(form.Passcode)
  210. if err != nil {
  211. ctx.ServerError("UserSignIn", err)
  212. return
  213. }
  214. if ok && twofa.LastUsedPasscode != form.Passcode {
  215. remember := ctx.Session.Get("twofaRemember").(bool)
  216. u, err := models.GetUserByID(id)
  217. if err != nil {
  218. ctx.ServerError("UserSignIn", err)
  219. return
  220. }
  221. if ctx.Session.Get("linkAccount") != nil {
  222. gothUser := ctx.Session.Get("linkAccountGothUser")
  223. if gothUser == nil {
  224. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  225. return
  226. }
  227. err = models.LinkAccountToUser(u, gothUser.(goth.User))
  228. if err != nil {
  229. ctx.ServerError("UserSignIn", err)
  230. return
  231. }
  232. }
  233. twofa.LastUsedPasscode = form.Passcode
  234. if err = models.UpdateTwoFactor(twofa); err != nil {
  235. ctx.ServerError("UserSignIn", err)
  236. return
  237. }
  238. handleSignIn(ctx, u, remember)
  239. return
  240. }
  241. ctx.RenderWithErr(ctx.Tr("auth.twofa_passcode_incorrect"), tplTwofa, auth.TwoFactorAuthForm{})
  242. }
  243. // TwoFactorScratch shows the scratch code form for two-factor authentication.
  244. func TwoFactorScratch(ctx *context.Context) {
  245. ctx.Data["Title"] = ctx.Tr("twofa_scratch")
  246. // Check auto-login.
  247. if checkAutoLogin(ctx) {
  248. return
  249. }
  250. // Ensure user is in a 2FA session.
  251. if ctx.Session.Get("twofaUid") == nil {
  252. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  253. return
  254. }
  255. ctx.HTML(200, tplTwofaScratch)
  256. }
  257. // TwoFactorScratchPost validates and invalidates a user's two-factor scratch token.
  258. func TwoFactorScratchPost(ctx *context.Context, form auth.TwoFactorScratchAuthForm) {
  259. ctx.Data["Title"] = ctx.Tr("twofa_scratch")
  260. // Ensure user is in a 2FA session.
  261. idSess := ctx.Session.Get("twofaUid")
  262. if idSess == nil {
  263. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  264. return
  265. }
  266. id := idSess.(int64)
  267. twofa, err := models.GetTwoFactorByUID(id)
  268. if err != nil {
  269. ctx.ServerError("UserSignIn", err)
  270. return
  271. }
  272. // Validate the passcode with the stored TOTP secret.
  273. if twofa.VerifyScratchToken(form.Token) {
  274. // Invalidate the scratch token.
  275. _, err = twofa.GenerateScratchToken()
  276. if err != nil {
  277. ctx.ServerError("UserSignIn", err)
  278. return
  279. }
  280. if err = models.UpdateTwoFactor(twofa); err != nil {
  281. ctx.ServerError("UserSignIn", err)
  282. return
  283. }
  284. remember := ctx.Session.Get("twofaRemember").(bool)
  285. u, err := models.GetUserByID(id)
  286. if err != nil {
  287. ctx.ServerError("UserSignIn", err)
  288. return
  289. }
  290. handleSignInFull(ctx, u, remember, false)
  291. ctx.Flash.Info(ctx.Tr("auth.twofa_scratch_used"))
  292. ctx.Redirect(setting.AppSubURL + "/user/settings/security")
  293. return
  294. }
  295. ctx.RenderWithErr(ctx.Tr("auth.twofa_scratch_token_incorrect"), tplTwofaScratch, auth.TwoFactorScratchAuthForm{})
  296. }
  297. // U2F shows the U2F login page
  298. func U2F(ctx *context.Context) {
  299. ctx.Data["Title"] = ctx.Tr("twofa")
  300. ctx.Data["RequireU2F"] = true
  301. // Check auto-login.
  302. if checkAutoLogin(ctx) {
  303. return
  304. }
  305. // Ensure user is in a 2FA session.
  306. if ctx.Session.Get("twofaUid") == nil {
  307. ctx.ServerError("UserSignIn", errors.New("not in U2F session"))
  308. return
  309. }
  310. ctx.HTML(200, tplU2F)
  311. }
  312. // U2FChallenge submits a sign challenge to the browser
  313. func U2FChallenge(ctx *context.Context) {
  314. // Ensure user is in a U2F session.
  315. idSess := ctx.Session.Get("twofaUid")
  316. if idSess == nil {
  317. ctx.ServerError("UserSignIn", errors.New("not in U2F session"))
  318. return
  319. }
  320. id := idSess.(int64)
  321. regs, err := models.GetU2FRegistrationsByUID(id)
  322. if err != nil {
  323. ctx.ServerError("UserSignIn", err)
  324. return
  325. }
  326. if len(regs) == 0 {
  327. ctx.ServerError("UserSignIn", errors.New("no device registered"))
  328. return
  329. }
  330. challenge, err := u2f.NewChallenge(setting.U2F.AppID, setting.U2F.TrustedFacets)
  331. if err = ctx.Session.Set("u2fChallenge", challenge); err != nil {
  332. ctx.ServerError("UserSignIn", err)
  333. return
  334. }
  335. ctx.JSON(200, challenge.SignRequest(regs.ToRegistrations()))
  336. }
  337. // U2FSign authenticates the user by signResp
  338. func U2FSign(ctx *context.Context, signResp u2f.SignResponse) {
  339. challSess := ctx.Session.Get("u2fChallenge")
  340. idSess := ctx.Session.Get("twofaUid")
  341. if challSess == nil || idSess == nil {
  342. ctx.ServerError("UserSignIn", errors.New("not in U2F session"))
  343. return
  344. }
  345. challenge := challSess.(*u2f.Challenge)
  346. id := idSess.(int64)
  347. regs, err := models.GetU2FRegistrationsByUID(id)
  348. if err != nil {
  349. ctx.ServerError("UserSignIn", err)
  350. return
  351. }
  352. for _, reg := range regs {
  353. r, err := reg.Parse()
  354. if err != nil {
  355. log.Fatal("parsing u2f registration: %v", err)
  356. continue
  357. }
  358. newCounter, authErr := r.Authenticate(signResp, *challenge, reg.Counter)
  359. if authErr == nil {
  360. reg.Counter = newCounter
  361. user, err := models.GetUserByID(id)
  362. if err != nil {
  363. ctx.ServerError("UserSignIn", err)
  364. return
  365. }
  366. remember := ctx.Session.Get("twofaRemember").(bool)
  367. if err := reg.UpdateCounter(); err != nil {
  368. ctx.ServerError("UserSignIn", err)
  369. return
  370. }
  371. if ctx.Session.Get("linkAccount") != nil {
  372. gothUser := ctx.Session.Get("linkAccountGothUser")
  373. if gothUser == nil {
  374. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  375. return
  376. }
  377. err = models.LinkAccountToUser(user, gothUser.(goth.User))
  378. if err != nil {
  379. ctx.ServerError("UserSignIn", err)
  380. return
  381. }
  382. }
  383. redirect := handleSignInFull(ctx, user, remember, false)
  384. if redirect == "" {
  385. redirect = setting.AppSubURL + "/"
  386. }
  387. ctx.PlainText(200, []byte(redirect))
  388. return
  389. }
  390. }
  391. ctx.Error(401)
  392. }
  393. // This handles the final part of the sign-in process of the user.
  394. func handleSignIn(ctx *context.Context, u *models.User, remember bool) {
  395. handleSignInFull(ctx, u, remember, true)
  396. }
  397. func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyRedirect bool) string {
  398. if remember {
  399. days := 86400 * setting.LogInRememberDays
  400. ctx.SetCookie(setting.CookieUserName, u.Name, days, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  401. ctx.SetSuperSecureCookie(base.EncodeMD5(u.Rands+u.Passwd),
  402. setting.CookieRememberName, u.Name, days, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  403. }
  404. ctx.Session.Delete("openid_verified_uri")
  405. ctx.Session.Delete("openid_signin_remember")
  406. ctx.Session.Delete("openid_determined_email")
  407. ctx.Session.Delete("openid_determined_username")
  408. ctx.Session.Delete("twofaUid")
  409. ctx.Session.Delete("twofaRemember")
  410. ctx.Session.Delete("u2fChallenge")
  411. ctx.Session.Delete("linkAccount")
  412. ctx.Session.Set("uid", u.ID)
  413. ctx.Session.Set("uname", u.Name)
  414. // Language setting of the user overwrites the one previously set
  415. // If the user does not have a locale set, we save the current one.
  416. if len(u.Language) == 0 {
  417. u.Language = ctx.Locale.Language()
  418. if err := models.UpdateUserCols(u, "language"); err != nil {
  419. log.Error(fmt.Sprintf("Error updating user language [user: %d, locale: %s]", u.ID, u.Language))
  420. return setting.AppSubURL + "/"
  421. }
  422. }
  423. ctx.SetCookie("lang", u.Language, nil, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  424. // Clear whatever CSRF has right now, force to generate a new one
  425. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  426. // Register last login
  427. u.SetLastLogin()
  428. if err := models.UpdateUserCols(u, "last_login_unix"); err != nil {
  429. ctx.ServerError("UpdateUserCols", err)
  430. return setting.AppSubURL + "/"
  431. }
  432. if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 && !util.IsExternalURL(redirectTo) {
  433. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  434. if obeyRedirect {
  435. ctx.RedirectToFirst(redirectTo)
  436. }
  437. return redirectTo
  438. }
  439. if obeyRedirect {
  440. ctx.Redirect(setting.AppSubURL + "/")
  441. }
  442. return setting.AppSubURL + "/"
  443. }
  444. // SignInOAuth handles the OAuth2 login buttons
  445. func SignInOAuth(ctx *context.Context) {
  446. provider := ctx.Params(":provider")
  447. loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider)
  448. if err != nil {
  449. ctx.ServerError("SignIn", err)
  450. return
  451. }
  452. // try to do a direct callback flow, so we don't authenticate the user again but use the valid accesstoken to get the user
  453. user, gothUser, err := oAuth2UserLoginCallback(loginSource, ctx.Req.Request, ctx.Resp)
  454. if err == nil && user != nil {
  455. // we got the user without going through the whole OAuth2 authentication flow again
  456. handleOAuth2SignIn(user, gothUser, ctx, err)
  457. return
  458. }
  459. err = oauth2.Auth(loginSource.Name, ctx.Req.Request, ctx.Resp)
  460. if err != nil {
  461. ctx.ServerError("SignIn", err)
  462. }
  463. // redirect is done in oauth2.Auth
  464. }
  465. // SignInOAuthCallback handles the callback from the given provider
  466. func SignInOAuthCallback(ctx *context.Context) {
  467. provider := ctx.Params(":provider")
  468. // first look if the provider is still active
  469. loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider)
  470. if err != nil {
  471. ctx.ServerError("SignIn", err)
  472. return
  473. }
  474. if loginSource == nil {
  475. ctx.ServerError("SignIn", errors.New("No valid provider found, check configured callback url in provider"))
  476. return
  477. }
  478. u, gothUser, err := oAuth2UserLoginCallback(loginSource, ctx.Req.Request, ctx.Resp)
  479. handleOAuth2SignIn(u, gothUser, ctx, err)
  480. }
  481. func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context, err error) {
  482. if err != nil {
  483. ctx.ServerError("UserSignIn", err)
  484. return
  485. }
  486. if u == nil {
  487. // no existing user is found, request attach or new account
  488. ctx.Session.Set("linkAccountGothUser", gothUser)
  489. ctx.Redirect(setting.AppSubURL + "/user/link_account")
  490. return
  491. }
  492. // If this user is enrolled in 2FA, we can't sign the user in just yet.
  493. // Instead, redirect them to the 2FA authentication page.
  494. _, err = models.GetTwoFactorByUID(u.ID)
  495. if err != nil {
  496. if models.IsErrTwoFactorNotEnrolled(err) {
  497. ctx.Session.Set("uid", u.ID)
  498. ctx.Session.Set("uname", u.Name)
  499. // Clear whatever CSRF has right now, force to generate a new one
  500. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  501. // Register last login
  502. u.SetLastLogin()
  503. if err := models.UpdateUserCols(u, "last_login_unix"); err != nil {
  504. ctx.ServerError("UpdateUserCols", err)
  505. return
  506. }
  507. if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 {
  508. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  509. ctx.RedirectToFirst(redirectTo)
  510. return
  511. }
  512. ctx.Redirect(setting.AppSubURL + "/")
  513. } else {
  514. ctx.ServerError("UserSignIn", err)
  515. }
  516. return
  517. }
  518. // User needs to use 2FA, save data and redirect to 2FA page.
  519. ctx.Session.Set("twofaUid", u.ID)
  520. ctx.Session.Set("twofaRemember", false)
  521. // If U2F is enrolled -> Redirect to U2F instead
  522. regs, err := models.GetU2FRegistrationsByUID(u.ID)
  523. if err == nil && len(regs) > 0 {
  524. ctx.Redirect(setting.AppSubURL + "/user/u2f")
  525. return
  526. }
  527. ctx.Redirect(setting.AppSubURL + "/user/two_factor")
  528. }
  529. // OAuth2UserLoginCallback attempts to handle the callback from the OAuth2 provider and if successful
  530. // login the user
  531. func oAuth2UserLoginCallback(loginSource *models.LoginSource, request *http.Request, response http.ResponseWriter) (*models.User, goth.User, error) {
  532. gothUser, err := oauth2.ProviderCallback(loginSource.Name, request, response)
  533. if err != nil {
  534. return nil, goth.User{}, err
  535. }
  536. user := &models.User{
  537. LoginName: gothUser.UserID,
  538. LoginType: models.LoginOAuth2,
  539. LoginSource: loginSource.ID,
  540. }
  541. hasUser, err := models.GetUser(user)
  542. if err != nil {
  543. return nil, goth.User{}, err
  544. }
  545. if hasUser {
  546. return user, goth.User{}, nil
  547. }
  548. // search in external linked users
  549. externalLoginUser := &models.ExternalLoginUser{
  550. ExternalID: gothUser.UserID,
  551. LoginSourceID: loginSource.ID,
  552. }
  553. hasUser, err = models.GetExternalLogin(externalLoginUser)
  554. if err != nil {
  555. return nil, goth.User{}, err
  556. }
  557. if hasUser {
  558. user, err = models.GetUserByID(externalLoginUser.UserID)
  559. return user, goth.User{}, err
  560. }
  561. // no user found to login
  562. return nil, gothUser, nil
  563. }
  564. // LinkAccount shows the page where the user can decide to login or create a new account
  565. func LinkAccount(ctx *context.Context) {
  566. ctx.Data["Title"] = ctx.Tr("link_account")
  567. ctx.Data["LinkAccountMode"] = true
  568. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
  569. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  570. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  571. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
  572. ctx.Data["ShowRegistrationButton"] = false
  573. // use this to set the right link into the signIn and signUp templates in the link_account template
  574. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
  575. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"
  576. gothUser := ctx.Session.Get("linkAccountGothUser")
  577. if gothUser == nil {
  578. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  579. return
  580. }
  581. uname := gothUser.(goth.User).NickName
  582. email := gothUser.(goth.User).Email
  583. ctx.Data["user_name"] = uname
  584. ctx.Data["email"] = email
  585. if len(email) != 0 {
  586. u, err := models.GetUserByEmail(email)
  587. if err != nil && !models.IsErrUserNotExist(err) {
  588. ctx.ServerError("UserSignIn", err)
  589. return
  590. }
  591. if u != nil {
  592. ctx.Data["user_exists"] = true
  593. }
  594. } else if len(uname) != 0 {
  595. u, err := models.GetUserByName(uname)
  596. if err != nil && !models.IsErrUserNotExist(err) {
  597. ctx.ServerError("UserSignIn", err)
  598. return
  599. }
  600. if u != nil {
  601. ctx.Data["user_exists"] = true
  602. }
  603. }
  604. ctx.HTML(200, tplLinkAccount)
  605. }
  606. // LinkAccountPostSignIn handle the coupling of external account with another account using signIn
  607. func LinkAccountPostSignIn(ctx *context.Context, signInForm auth.SignInForm) {
  608. ctx.Data["Title"] = ctx.Tr("link_account")
  609. ctx.Data["LinkAccountMode"] = true
  610. ctx.Data["LinkAccountModeSignIn"] = true
  611. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
  612. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  613. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  614. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
  615. ctx.Data["ShowRegistrationButton"] = false
  616. // use this to set the right link into the signIn and signUp templates in the link_account template
  617. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
  618. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"
  619. gothUser := ctx.Session.Get("linkAccountGothUser")
  620. if gothUser == nil {
  621. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  622. return
  623. }
  624. if ctx.HasError() {
  625. ctx.HTML(200, tplLinkAccount)
  626. return
  627. }
  628. u, err := models.UserSignIn(signInForm.UserName, signInForm.Password)
  629. if err != nil {
  630. if models.IsErrUserNotExist(err) {
  631. ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplLinkAccount, &signInForm)
  632. } else {
  633. ctx.ServerError("UserLinkAccount", err)
  634. }
  635. return
  636. }
  637. // If this user is enrolled in 2FA, we can't sign the user in just yet.
  638. // Instead, redirect them to the 2FA authentication page.
  639. _, err = models.GetTwoFactorByUID(u.ID)
  640. if err != nil {
  641. if models.IsErrTwoFactorNotEnrolled(err) {
  642. err = models.LinkAccountToUser(u, gothUser.(goth.User))
  643. if err != nil {
  644. ctx.ServerError("UserLinkAccount", err)
  645. } else {
  646. handleSignIn(ctx, u, signInForm.Remember)
  647. }
  648. } else {
  649. ctx.ServerError("UserLinkAccount", err)
  650. }
  651. return
  652. }
  653. // User needs to use 2FA, save data and redirect to 2FA page.
  654. ctx.Session.Set("twofaUid", u.ID)
  655. ctx.Session.Set("twofaRemember", signInForm.Remember)
  656. ctx.Session.Set("linkAccount", true)
  657. // If U2F is enrolled -> Redirect to U2F instead
  658. regs, err := models.GetU2FRegistrationsByUID(u.ID)
  659. if err == nil && len(regs) > 0 {
  660. ctx.Redirect(setting.AppSubURL + "/user/u2f")
  661. return
  662. }
  663. ctx.Redirect(setting.AppSubURL + "/user/two_factor")
  664. }
  665. // LinkAccountPostRegister handle the creation of a new account for an external account using signUp
  666. func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterForm) {
  667. ctx.Data["Title"] = ctx.Tr("link_account")
  668. ctx.Data["LinkAccountMode"] = true
  669. ctx.Data["LinkAccountModeRegister"] = true
  670. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
  671. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  672. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  673. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
  674. ctx.Data["ShowRegistrationButton"] = false
  675. // use this to set the right link into the signIn and signUp templates in the link_account template
  676. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
  677. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"
  678. gothUser := ctx.Session.Get("linkAccountGothUser")
  679. if gothUser == nil {
  680. ctx.ServerError("UserSignUp", errors.New("not in LinkAccount session"))
  681. return
  682. }
  683. if ctx.HasError() {
  684. ctx.HTML(200, tplLinkAccount)
  685. return
  686. }
  687. if setting.Service.DisableRegistration {
  688. ctx.Error(403)
  689. return
  690. }
  691. if setting.Service.EnableCaptcha && setting.Service.CaptchaType == setting.ImageCaptcha && !cpt.VerifyReq(ctx.Req) {
  692. ctx.Data["Err_Captcha"] = true
  693. ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplLinkAccount, &form)
  694. return
  695. }
  696. if setting.Service.EnableCaptcha && setting.Service.CaptchaType == setting.ReCaptcha {
  697. valid, _ := recaptcha.Verify(form.GRecaptchaResponse)
  698. if !valid {
  699. ctx.Data["Err_Captcha"] = true
  700. ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplLinkAccount, &form)
  701. return
  702. }
  703. }
  704. if (len(strings.TrimSpace(form.Password)) > 0 || len(strings.TrimSpace(form.Retype)) > 0) && form.Password != form.Retype {
  705. ctx.Data["Err_Password"] = true
  706. ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplLinkAccount, &form)
  707. return
  708. }
  709. if len(strings.TrimSpace(form.Password)) > 0 && len(form.Password) < setting.MinPasswordLength {
  710. ctx.Data["Err_Password"] = true
  711. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplLinkAccount, &form)
  712. return
  713. }
  714. loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.(goth.User).Provider)
  715. if err != nil {
  716. ctx.ServerError("CreateUser", err)
  717. }
  718. u := &models.User{
  719. Name: form.UserName,
  720. Email: form.Email,
  721. Passwd: form.Password,
  722. IsActive: !setting.Service.RegisterEmailConfirm,
  723. LoginType: models.LoginOAuth2,
  724. LoginSource: loginSource.ID,
  725. LoginName: gothUser.(goth.User).UserID,
  726. }
  727. if err := models.CreateUser(u); err != nil {
  728. switch {
  729. case models.IsErrUserAlreadyExist(err):
  730. ctx.Data["Err_UserName"] = true
  731. ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplLinkAccount, &form)
  732. case models.IsErrEmailAlreadyUsed(err):
  733. ctx.Data["Err_Email"] = true
  734. ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplLinkAccount, &form)
  735. case models.IsErrNameReserved(err):
  736. ctx.Data["Err_UserName"] = true
  737. ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tplLinkAccount, &form)
  738. case models.IsErrNamePatternNotAllowed(err):
  739. ctx.Data["Err_UserName"] = true
  740. ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplLinkAccount, &form)
  741. default:
  742. ctx.ServerError("CreateUser", err)
  743. }
  744. return
  745. }
  746. log.Trace("Account created: %s", u.Name)
  747. // Auto-set admin for the only user.
  748. if models.CountUsers() == 1 {
  749. u.IsAdmin = true
  750. u.IsActive = true
  751. u.SetLastLogin()
  752. if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil {
  753. ctx.ServerError("UpdateUser", err)
  754. return
  755. }
  756. }
  757. // Send confirmation email
  758. if setting.Service.RegisterEmailConfirm && u.ID > 1 {
  759. models.SendActivateAccountMail(ctx.Context, u)
  760. ctx.Data["IsSendRegisterMail"] = true
  761. ctx.Data["Email"] = u.Email
  762. ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
  763. ctx.HTML(200, TplActivate)
  764. if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
  765. log.Error("Set cache(MailResendLimit) fail: %v", err)
  766. }
  767. return
  768. }
  769. ctx.Redirect(setting.AppSubURL + "/user/login")
  770. }
  771. // SignOut sign out from login status
  772. func SignOut(ctx *context.Context) {
  773. ctx.Session.Delete("uid")
  774. ctx.Session.Delete("uname")
  775. ctx.Session.Delete("socialId")
  776. ctx.Session.Delete("socialName")
  777. ctx.Session.Delete("socialEmail")
  778. ctx.SetCookie(setting.CookieUserName, "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  779. ctx.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  780. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  781. ctx.SetCookie("lang", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true) // Setting the lang cookie will trigger the middleware to reset the language ot previous state.
  782. ctx.Redirect(setting.AppSubURL + "/")
  783. }
  784. // SignUp render the register page
  785. func SignUp(ctx *context.Context) {
  786. ctx.Data["Title"] = ctx.Tr("sign_up")
  787. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
  788. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
  789. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  790. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  791. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
  792. ctx.HTML(200, tplSignUp)
  793. }
  794. // SignUpPost response for sign up information submission
  795. func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterForm) {
  796. ctx.Data["Title"] = ctx.Tr("sign_up")
  797. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
  798. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
  799. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  800. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  801. //Permission denied if DisableRegistration or AllowOnlyExternalRegistration options are true
  802. if !setting.Service.ShowRegistrationButton {
  803. ctx.Error(403)
  804. return
  805. }
  806. if ctx.HasError() {
  807. ctx.HTML(200, tplSignUp)
  808. return
  809. }
  810. if setting.Service.EnableCaptcha && setting.Service.CaptchaType == setting.ImageCaptcha && !cpt.VerifyReq(ctx.Req) {
  811. ctx.Data["Err_Captcha"] = true
  812. ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplSignUp, &form)
  813. return
  814. }
  815. if setting.Service.EnableCaptcha && setting.Service.CaptchaType == setting.ReCaptcha {
  816. valid, _ := recaptcha.Verify(form.GRecaptchaResponse)
  817. if !valid {
  818. ctx.Data["Err_Captcha"] = true
  819. ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplSignUp, &form)
  820. return
  821. }
  822. }
  823. if !form.IsEmailDomainWhitelisted() {
  824. ctx.RenderWithErr(ctx.Tr("auth.email_domain_blacklisted"), tplSignUp, &form)
  825. return
  826. }
  827. if form.Password != form.Retype {
  828. ctx.Data["Err_Password"] = true
  829. ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplSignUp, &form)
  830. return
  831. }
  832. if len(form.Password) < setting.MinPasswordLength {
  833. ctx.Data["Err_Password"] = true
  834. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplSignUp, &form)
  835. return
  836. }
  837. u := &models.User{
  838. Name: form.UserName,
  839. Email: form.Email,
  840. Passwd: form.Password,
  841. IsActive: !setting.Service.RegisterEmailConfirm,
  842. }
  843. if err := models.CreateUser(u); err != nil {
  844. switch {
  845. case models.IsErrUserAlreadyExist(err):
  846. ctx.Data["Err_UserName"] = true
  847. ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplSignUp, &form)
  848. case models.IsErrEmailAlreadyUsed(err):
  849. ctx.Data["Err_Email"] = true
  850. ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignUp, &form)
  851. case models.IsErrNameReserved(err):
  852. ctx.Data["Err_UserName"] = true
  853. ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tplSignUp, &form)
  854. case models.IsErrNamePatternNotAllowed(err):
  855. ctx.Data["Err_UserName"] = true
  856. ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSignUp, &form)
  857. default:
  858. ctx.ServerError("CreateUser", err)
  859. }
  860. return
  861. }
  862. log.Trace("Account created: %s", u.Name)
  863. // Auto-set admin for the only user.
  864. if models.CountUsers() == 1 {
  865. u.IsAdmin = true
  866. u.IsActive = true
  867. u.SetLastLogin()
  868. if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil {
  869. ctx.ServerError("UpdateUser", err)
  870. return
  871. }
  872. }
  873. // Send confirmation email, no need for social account.
  874. if setting.Service.RegisterEmailConfirm && u.ID > 1 {
  875. models.SendActivateAccountMail(ctx.Context, u)
  876. ctx.Data["IsSendRegisterMail"] = true
  877. ctx.Data["Email"] = u.Email
  878. ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
  879. ctx.HTML(200, TplActivate)
  880. if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
  881. log.Error("Set cache(MailResendLimit) fail: %v", err)
  882. }
  883. return
  884. }
  885. ctx.Flash.Success(ctx.Tr("auth.sign_up_successful"))
  886. handleSignInFull(ctx, u, false, true)
  887. }
  888. // Activate render activate user page
  889. func Activate(ctx *context.Context) {
  890. code := ctx.Query("code")
  891. if len(code) == 0 {
  892. ctx.Data["IsActivatePage"] = true
  893. if ctx.User.IsActive {
  894. ctx.Error(404)
  895. return
  896. }
  897. // Resend confirmation email.
  898. if setting.Service.RegisterEmailConfirm {
  899. if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) {
  900. ctx.Data["ResendLimited"] = true
  901. } else {
  902. ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
  903. models.SendActivateAccountMail(ctx.Context, ctx.User)
  904. if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
  905. log.Error("Set cache(MailResendLimit) fail: %v", err)
  906. }
  907. }
  908. } else {
  909. ctx.Data["ServiceNotEnabled"] = true
  910. }
  911. ctx.HTML(200, TplActivate)
  912. return
  913. }
  914. // Verify code.
  915. if user := models.VerifyUserActiveCode(code); user != nil {
  916. user.IsActive = true
  917. var err error
  918. if user.Rands, err = models.GetUserSalt(); err != nil {
  919. ctx.ServerError("UpdateUser", err)
  920. return
  921. }
  922. if err := models.UpdateUserCols(user, "is_active", "rands"); err != nil {
  923. if models.IsErrUserNotExist(err) {
  924. ctx.Error(404)
  925. } else {
  926. ctx.ServerError("UpdateUser", err)
  927. }
  928. return
  929. }
  930. log.Trace("User activated: %s", user.Name)
  931. ctx.Session.Set("uid", user.ID)
  932. ctx.Session.Set("uname", user.Name)
  933. ctx.Flash.Success(ctx.Tr("auth.account_activated"))
  934. ctx.Redirect(setting.AppSubURL + "/")
  935. return
  936. }
  937. ctx.Data["IsActivateFailed"] = true
  938. ctx.HTML(200, TplActivate)
  939. }
  940. // ActivateEmail render the activate email page
  941. func ActivateEmail(ctx *context.Context) {
  942. code := ctx.Query("code")
  943. emailStr := ctx.Query("email")
  944. // Verify code.
  945. if email := models.VerifyActiveEmailCode(code, emailStr); email != nil {
  946. if err := email.Activate(); err != nil {
  947. ctx.ServerError("ActivateEmail", err)
  948. }
  949. log.Trace("Email activated: %s", email.Email)
  950. ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
  951. }
  952. ctx.Redirect(setting.AppSubURL + "/user/settings/email")
  953. return
  954. }
  955. // ForgotPasswd render the forget pasword page
  956. func ForgotPasswd(ctx *context.Context) {
  957. ctx.Data["Title"] = ctx.Tr("auth.forgot_password_title")
  958. if setting.MailService == nil {
  959. ctx.Data["IsResetDisable"] = true
  960. ctx.HTML(200, tplForgotPassword)
  961. return
  962. }
  963. email := ctx.Query("email")
  964. ctx.Data["Email"] = email
  965. ctx.Data["IsResetRequest"] = true
  966. ctx.HTML(200, tplForgotPassword)
  967. }
  968. // ForgotPasswdPost response for forget password request
  969. func ForgotPasswdPost(ctx *context.Context) {
  970. ctx.Data["Title"] = ctx.Tr("auth.forgot_password_title")
  971. if setting.MailService == nil {
  972. ctx.NotFound("ForgotPasswdPost", nil)
  973. return
  974. }
  975. ctx.Data["IsResetRequest"] = true
  976. email := ctx.Query("email")
  977. ctx.Data["Email"] = email
  978. u, err := models.GetUserByEmail(email)
  979. if err != nil {
  980. if models.IsErrUserNotExist(err) {
  981. ctx.Data["ResetPwdCodeLives"] = base.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
  982. ctx.Data["IsResetSent"] = true
  983. ctx.HTML(200, tplForgotPassword)
  984. return
  985. }
  986. ctx.ServerError("user.ResetPasswd(check existence)", err)
  987. return
  988. }
  989. if !u.IsLocal() && !u.IsOAuth2() {
  990. ctx.Data["Err_Email"] = true
  991. ctx.RenderWithErr(ctx.Tr("auth.non_local_account"), tplForgotPassword, nil)
  992. return
  993. }
  994. if ctx.Cache.IsExist("MailResendLimit_" + u.LowerName) {
  995. ctx.Data["ResendLimited"] = true
  996. ctx.HTML(200, tplForgotPassword)
  997. return
  998. }
  999. models.SendResetPasswordMail(ctx.Context, u)
  1000. if err = ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
  1001. log.Error("Set cache(MailResendLimit) fail: %v", err)
  1002. }
  1003. ctx.Data["ResetPwdCodeLives"] = base.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
  1004. ctx.Data["IsResetSent"] = true
  1005. ctx.HTML(200, tplForgotPassword)
  1006. }
  1007. // ResetPasswd render the reset password page
  1008. func ResetPasswd(ctx *context.Context) {
  1009. ctx.Data["Title"] = ctx.Tr("auth.reset_password")
  1010. code := ctx.Query("code")
  1011. if len(code) == 0 {
  1012. ctx.Error(404)
  1013. return
  1014. }
  1015. ctx.Data["Code"] = code
  1016. if u := models.VerifyUserActiveCode(code); u != nil {
  1017. ctx.Data["IsResetForm"] = true
  1018. }
  1019. ctx.HTML(200, tplResetPassword)
  1020. }
  1021. // ResetPasswdPost response from reset password request
  1022. func ResetPasswdPost(ctx *context.Context) {
  1023. ctx.Data["Title"] = ctx.Tr("auth.reset_password")
  1024. code := ctx.Query("code")
  1025. if len(code) == 0 {
  1026. ctx.Error(404)
  1027. return
  1028. }
  1029. ctx.Data["Code"] = code
  1030. if u := models.VerifyUserActiveCode(code); u != nil {
  1031. // Validate password length.
  1032. passwd := ctx.Query("password")
  1033. if len(passwd) < setting.MinPasswordLength {
  1034. ctx.Data["IsResetForm"] = true
  1035. ctx.Data["Err_Password"] = true
  1036. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplResetPassword, nil)
  1037. return
  1038. }
  1039. var err error
  1040. if u.Rands, err = models.GetUserSalt(); err != nil {
  1041. ctx.ServerError("UpdateUser", err)
  1042. return
  1043. }
  1044. if u.Salt, err = models.GetUserSalt(); err != nil {
  1045. ctx.ServerError("UpdateUser", err)
  1046. return
  1047. }
  1048. u.HashPassword(passwd)
  1049. u.MustChangePassword = false
  1050. if err := models.UpdateUserCols(u, "must_change_password", "passwd", "rands", "salt"); err != nil {
  1051. ctx.ServerError("UpdateUser", err)
  1052. return
  1053. }
  1054. log.Trace("User password reset: %s", u.Name)
  1055. ctx.Redirect(setting.AppSubURL + "/user/login")
  1056. return
  1057. }
  1058. ctx.Data["IsResetFailed"] = true
  1059. ctx.HTML(200, tplResetPassword)
  1060. }
  1061. // MustChangePassword renders the page to change a user's password
  1062. func MustChangePassword(ctx *context.Context) {
  1063. ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
  1064. ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password"
  1065. ctx.HTML(200, tplMustChangePassword)
  1066. }
  1067. // MustChangePasswordPost response for updating a user's password after his/her
  1068. // account was created by an admin
  1069. func MustChangePasswordPost(ctx *context.Context, cpt *captcha.Captcha, form auth.MustChangePasswordForm) {
  1070. ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
  1071. ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password"
  1072. if ctx.HasError() {
  1073. ctx.HTML(200, tplMustChangePassword)
  1074. return
  1075. }
  1076. u := ctx.User
  1077. // Make sure only requests for users who are eligible to change their password via
  1078. // this method passes through
  1079. if !u.MustChangePassword {
  1080. ctx.ServerError("MustUpdatePassword", errors.New("cannot update password.. Please visit the settings page"))
  1081. return
  1082. }
  1083. if form.Password != form.Retype {
  1084. ctx.Data["Err_Password"] = true
  1085. ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplMustChangePassword, &form)
  1086. return
  1087. }
  1088. if len(form.Password) < setting.MinPasswordLength {
  1089. ctx.Data["Err_Password"] = true
  1090. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplMustChangePassword, &form)
  1091. return
  1092. }
  1093. var err error
  1094. if u.Salt, err = models.GetUserSalt(); err != nil {
  1095. ctx.ServerError("UpdateUser", err)
  1096. return
  1097. }
  1098. u.HashPassword(form.Password)
  1099. u.MustChangePassword = false
  1100. if err := models.UpdateUserCols(u, "must_change_password", "passwd", "salt"); err != nil {
  1101. ctx.ServerError("UpdateUser", err)
  1102. return
  1103. }
  1104. ctx.Flash.Success(ctx.Tr("settings.change_password_success"))
  1105. log.Trace("User updated password: %s", u.Name)
  1106. if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 && !util.IsExternalURL(redirectTo) {
  1107. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL)
  1108. ctx.RedirectToFirst(redirectTo)
  1109. return
  1110. }
  1111. ctx.Redirect(setting.AppSubURL + "/")
  1112. }