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

auth.go 44 kB

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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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
6 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
6 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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)
8 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
6 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)
8 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)
8 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
6 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
6 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)
8 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
6 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  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/timeutil"
  20. "code.gitea.io/gitea/modules/util"
  21. "code.gitea.io/gitea/services/mailer"
  22. "gitea.com/macaron/captcha"
  23. "github.com/markbates/goth"
  24. "github.com/tstranex/u2f"
  25. )
  26. const (
  27. // tplMustChangePassword template for updating a user's password
  28. tplMustChangePassword = "user/auth/change_passwd"
  29. // tplSignIn template for sign in page
  30. tplSignIn base.TplName = "user/auth/signin"
  31. // tplSignUp template path for sign up page
  32. tplSignUp base.TplName = "user/auth/signup"
  33. // TplActivate template path for activate user
  34. TplActivate base.TplName = "user/auth/activate"
  35. tplForgotPassword base.TplName = "user/auth/forgot_passwd"
  36. tplResetPassword base.TplName = "user/auth/reset_passwd"
  37. tplTwofa base.TplName = "user/auth/twofa"
  38. tplTwofaScratch base.TplName = "user/auth/twofa_scratch"
  39. tplLinkAccount base.TplName = "user/auth/link_account"
  40. tplU2F base.TplName = "user/auth/u2f"
  41. )
  42. // AutoSignIn reads cookie and try to auto-login.
  43. func AutoSignIn(ctx *context.Context) (bool, error) {
  44. if !models.HasEngine {
  45. return false, nil
  46. }
  47. uname := ctx.GetCookie(setting.CookieUserName)
  48. if len(uname) == 0 {
  49. return false, nil
  50. }
  51. isSucceed := false
  52. defer func() {
  53. if !isSucceed {
  54. log.Trace("auto-login cookie cleared: %s", uname)
  55. ctx.SetCookie(setting.CookieUserName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  56. ctx.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  57. }
  58. }()
  59. u, err := models.GetUserByName(uname)
  60. if err != nil {
  61. if !models.IsErrUserNotExist(err) {
  62. return false, fmt.Errorf("GetUserByName: %v", err)
  63. }
  64. return false, nil
  65. }
  66. if val, ok := ctx.GetSuperSecureCookie(
  67. base.EncodeMD5(u.Rands+u.Passwd), setting.CookieRememberName); !ok || val != u.Name {
  68. return false, nil
  69. }
  70. isSucceed = true
  71. err = ctx.Session.Set("uid", u.ID)
  72. if err != nil {
  73. return false, err
  74. }
  75. err = ctx.Session.Set("uname", u.Name)
  76. if err != nil {
  77. return false, err
  78. }
  79. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  80. return true, nil
  81. }
  82. func checkAutoLogin(ctx *context.Context) bool {
  83. // Check auto-login.
  84. isSucceed, err := AutoSignIn(ctx)
  85. if err != nil {
  86. ctx.ServerError("AutoSignIn", err)
  87. return true
  88. }
  89. redirectTo := ctx.Query("redirect_to")
  90. if len(redirectTo) > 0 {
  91. ctx.SetCookie("redirect_to", redirectTo, 0, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  92. } else {
  93. redirectTo = ctx.GetCookie("redirect_to")
  94. }
  95. if isSucceed {
  96. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  97. ctx.RedirectToFirst(redirectTo, setting.AppSubURL+string(setting.LandingPageURL))
  98. return true
  99. }
  100. return false
  101. }
  102. // SignIn render sign in page
  103. func SignIn(ctx *context.Context) {
  104. ctx.Data["Title"] = ctx.Tr("sign_in")
  105. // Check auto-login.
  106. if checkAutoLogin(ctx) {
  107. return
  108. }
  109. orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers()
  110. if err != nil {
  111. ctx.ServerError("UserSignIn", err)
  112. return
  113. }
  114. ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names
  115. ctx.Data["OAuth2Providers"] = oauth2Providers
  116. ctx.Data["Title"] = ctx.Tr("sign_in")
  117. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login"
  118. ctx.Data["PageIsSignIn"] = true
  119. ctx.Data["PageIsLogin"] = true
  120. ctx.HTML(200, tplSignIn)
  121. }
  122. // SignInPost response for sign in request
  123. func SignInPost(ctx *context.Context, form auth.SignInForm) {
  124. ctx.Data["Title"] = ctx.Tr("sign_in")
  125. orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers()
  126. if err != nil {
  127. ctx.ServerError("UserSignIn", err)
  128. return
  129. }
  130. ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names
  131. ctx.Data["OAuth2Providers"] = oauth2Providers
  132. ctx.Data["Title"] = ctx.Tr("sign_in")
  133. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login"
  134. ctx.Data["PageIsSignIn"] = true
  135. ctx.Data["PageIsLogin"] = true
  136. if ctx.HasError() {
  137. ctx.HTML(200, tplSignIn)
  138. return
  139. }
  140. u, err := models.UserSignIn(form.UserName, form.Password)
  141. if err != nil {
  142. if models.IsErrUserNotExist(err) {
  143. ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form)
  144. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  145. } else if models.IsErrEmailAlreadyUsed(err) {
  146. ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignIn, &form)
  147. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  148. } else if models.IsErrUserProhibitLogin(err) {
  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. } else if models.IsErrUserInactive(err) {
  153. if setting.Service.RegisterEmailConfirm {
  154. ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
  155. ctx.HTML(200, TplActivate)
  156. } else {
  157. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  158. ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
  159. ctx.HTML(200, "user/auth/prohibit_login")
  160. }
  161. } else {
  162. ctx.ServerError("UserSignIn", err)
  163. }
  164. return
  165. }
  166. // If this user is enrolled in 2FA, we can't sign the user in just yet.
  167. // Instead, redirect them to the 2FA authentication page.
  168. _, err = models.GetTwoFactorByUID(u.ID)
  169. if err != nil {
  170. if models.IsErrTwoFactorNotEnrolled(err) {
  171. handleSignIn(ctx, u, form.Remember)
  172. } else {
  173. ctx.ServerError("UserSignIn", err)
  174. }
  175. return
  176. }
  177. // User needs to use 2FA, save data and redirect to 2FA page.
  178. err = ctx.Session.Set("twofaUid", u.ID)
  179. if err != nil {
  180. ctx.ServerError("UserSignIn", err)
  181. return
  182. }
  183. err = ctx.Session.Set("twofaRemember", form.Remember)
  184. if err != nil {
  185. ctx.ServerError("UserSignIn", err)
  186. return
  187. }
  188. regs, err := models.GetU2FRegistrationsByUID(u.ID)
  189. if err == nil && len(regs) > 0 {
  190. ctx.Redirect(setting.AppSubURL + "/user/u2f")
  191. return
  192. }
  193. ctx.Redirect(setting.AppSubURL + "/user/two_factor")
  194. }
  195. // TwoFactor shows the user a two-factor authentication page.
  196. func TwoFactor(ctx *context.Context) {
  197. ctx.Data["Title"] = ctx.Tr("twofa")
  198. // Check auto-login.
  199. if checkAutoLogin(ctx) {
  200. return
  201. }
  202. // Ensure user is in a 2FA session.
  203. if ctx.Session.Get("twofaUid") == nil {
  204. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  205. return
  206. }
  207. ctx.HTML(200, tplTwofa)
  208. }
  209. // TwoFactorPost validates a user's two-factor authentication token.
  210. func TwoFactorPost(ctx *context.Context, form auth.TwoFactorAuthForm) {
  211. ctx.Data["Title"] = ctx.Tr("twofa")
  212. // Ensure user is in a 2FA session.
  213. idSess := ctx.Session.Get("twofaUid")
  214. if idSess == nil {
  215. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  216. return
  217. }
  218. id := idSess.(int64)
  219. twofa, err := models.GetTwoFactorByUID(id)
  220. if err != nil {
  221. ctx.ServerError("UserSignIn", err)
  222. return
  223. }
  224. // Validate the passcode with the stored TOTP secret.
  225. ok, err := twofa.ValidateTOTP(form.Passcode)
  226. if err != nil {
  227. ctx.ServerError("UserSignIn", err)
  228. return
  229. }
  230. if ok && twofa.LastUsedPasscode != form.Passcode {
  231. remember := ctx.Session.Get("twofaRemember").(bool)
  232. u, err := models.GetUserByID(id)
  233. if err != nil {
  234. ctx.ServerError("UserSignIn", err)
  235. return
  236. }
  237. if ctx.Session.Get("linkAccount") != nil {
  238. gothUser := ctx.Session.Get("linkAccountGothUser")
  239. if gothUser == nil {
  240. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  241. return
  242. }
  243. err = models.LinkAccountToUser(u, gothUser.(goth.User))
  244. if err != nil {
  245. ctx.ServerError("UserSignIn", err)
  246. return
  247. }
  248. }
  249. twofa.LastUsedPasscode = form.Passcode
  250. if err = models.UpdateTwoFactor(twofa); err != nil {
  251. ctx.ServerError("UserSignIn", err)
  252. return
  253. }
  254. handleSignIn(ctx, u, remember)
  255. return
  256. }
  257. ctx.RenderWithErr(ctx.Tr("auth.twofa_passcode_incorrect"), tplTwofa, auth.TwoFactorAuthForm{})
  258. }
  259. // TwoFactorScratch shows the scratch code form for two-factor authentication.
  260. func TwoFactorScratch(ctx *context.Context) {
  261. ctx.Data["Title"] = ctx.Tr("twofa_scratch")
  262. // Check auto-login.
  263. if checkAutoLogin(ctx) {
  264. return
  265. }
  266. // Ensure user is in a 2FA session.
  267. if ctx.Session.Get("twofaUid") == nil {
  268. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  269. return
  270. }
  271. ctx.HTML(200, tplTwofaScratch)
  272. }
  273. // TwoFactorScratchPost validates and invalidates a user's two-factor scratch token.
  274. func TwoFactorScratchPost(ctx *context.Context, form auth.TwoFactorScratchAuthForm) {
  275. ctx.Data["Title"] = ctx.Tr("twofa_scratch")
  276. // Ensure user is in a 2FA session.
  277. idSess := ctx.Session.Get("twofaUid")
  278. if idSess == nil {
  279. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  280. return
  281. }
  282. id := idSess.(int64)
  283. twofa, err := models.GetTwoFactorByUID(id)
  284. if err != nil {
  285. ctx.ServerError("UserSignIn", err)
  286. return
  287. }
  288. // Validate the passcode with the stored TOTP secret.
  289. if twofa.VerifyScratchToken(form.Token) {
  290. // Invalidate the scratch token.
  291. _, err = twofa.GenerateScratchToken()
  292. if err != nil {
  293. ctx.ServerError("UserSignIn", err)
  294. return
  295. }
  296. if err = models.UpdateTwoFactor(twofa); err != nil {
  297. ctx.ServerError("UserSignIn", err)
  298. return
  299. }
  300. remember := ctx.Session.Get("twofaRemember").(bool)
  301. u, err := models.GetUserByID(id)
  302. if err != nil {
  303. ctx.ServerError("UserSignIn", err)
  304. return
  305. }
  306. handleSignInFull(ctx, u, remember, false)
  307. ctx.Flash.Info(ctx.Tr("auth.twofa_scratch_used"))
  308. ctx.Redirect(setting.AppSubURL + "/user/settings/security")
  309. return
  310. }
  311. ctx.RenderWithErr(ctx.Tr("auth.twofa_scratch_token_incorrect"), tplTwofaScratch, auth.TwoFactorScratchAuthForm{})
  312. }
  313. // U2F shows the U2F login page
  314. func U2F(ctx *context.Context) {
  315. ctx.Data["Title"] = ctx.Tr("twofa")
  316. ctx.Data["RequireU2F"] = true
  317. // Check auto-login.
  318. if checkAutoLogin(ctx) {
  319. return
  320. }
  321. // Ensure user is in a 2FA session.
  322. if ctx.Session.Get("twofaUid") == nil {
  323. ctx.ServerError("UserSignIn", errors.New("not in U2F session"))
  324. return
  325. }
  326. ctx.HTML(200, tplU2F)
  327. }
  328. // U2FChallenge submits a sign challenge to the browser
  329. func U2FChallenge(ctx *context.Context) {
  330. // Ensure user is in a U2F session.
  331. idSess := ctx.Session.Get("twofaUid")
  332. if idSess == nil {
  333. ctx.ServerError("UserSignIn", errors.New("not in U2F session"))
  334. return
  335. }
  336. id := idSess.(int64)
  337. regs, err := models.GetU2FRegistrationsByUID(id)
  338. if err != nil {
  339. ctx.ServerError("UserSignIn", err)
  340. return
  341. }
  342. if len(regs) == 0 {
  343. ctx.ServerError("UserSignIn", errors.New("no device registered"))
  344. return
  345. }
  346. challenge, err := u2f.NewChallenge(setting.U2F.AppID, setting.U2F.TrustedFacets)
  347. if err != nil {
  348. ctx.ServerError("u2f.NewChallenge", err)
  349. return
  350. }
  351. if err = ctx.Session.Set("u2fChallenge", challenge); err != nil {
  352. ctx.ServerError("UserSignIn", err)
  353. return
  354. }
  355. ctx.JSON(200, challenge.SignRequest(regs.ToRegistrations()))
  356. }
  357. // U2FSign authenticates the user by signResp
  358. func U2FSign(ctx *context.Context, signResp u2f.SignResponse) {
  359. challSess := ctx.Session.Get("u2fChallenge")
  360. idSess := ctx.Session.Get("twofaUid")
  361. if challSess == nil || idSess == nil {
  362. ctx.ServerError("UserSignIn", errors.New("not in U2F session"))
  363. return
  364. }
  365. challenge := challSess.(*u2f.Challenge)
  366. id := idSess.(int64)
  367. regs, err := models.GetU2FRegistrationsByUID(id)
  368. if err != nil {
  369. ctx.ServerError("UserSignIn", err)
  370. return
  371. }
  372. for _, reg := range regs {
  373. r, err := reg.Parse()
  374. if err != nil {
  375. log.Fatal("parsing u2f registration: %v", err)
  376. continue
  377. }
  378. newCounter, authErr := r.Authenticate(signResp, *challenge, reg.Counter)
  379. if authErr == nil {
  380. reg.Counter = newCounter
  381. user, err := models.GetUserByID(id)
  382. if err != nil {
  383. ctx.ServerError("UserSignIn", err)
  384. return
  385. }
  386. remember := ctx.Session.Get("twofaRemember").(bool)
  387. if err := reg.UpdateCounter(); err != nil {
  388. ctx.ServerError("UserSignIn", err)
  389. return
  390. }
  391. if ctx.Session.Get("linkAccount") != nil {
  392. gothUser := ctx.Session.Get("linkAccountGothUser")
  393. if gothUser == nil {
  394. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  395. return
  396. }
  397. err = models.LinkAccountToUser(user, gothUser.(goth.User))
  398. if err != nil {
  399. ctx.ServerError("UserSignIn", err)
  400. return
  401. }
  402. }
  403. redirect := handleSignInFull(ctx, user, remember, false)
  404. if redirect == "" {
  405. redirect = setting.AppSubURL + "/"
  406. }
  407. ctx.PlainText(200, []byte(redirect))
  408. return
  409. }
  410. }
  411. ctx.Error(401)
  412. }
  413. // This handles the final part of the sign-in process of the user.
  414. func handleSignIn(ctx *context.Context, u *models.User, remember bool) {
  415. handleSignInFull(ctx, u, remember, true)
  416. }
  417. func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyRedirect bool) string {
  418. if remember {
  419. days := 86400 * setting.LogInRememberDays
  420. ctx.SetCookie(setting.CookieUserName, u.Name, days, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  421. ctx.SetSuperSecureCookie(base.EncodeMD5(u.Rands+u.Passwd),
  422. setting.CookieRememberName, u.Name, days, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  423. }
  424. _ = ctx.Session.Delete("openid_verified_uri")
  425. _ = ctx.Session.Delete("openid_signin_remember")
  426. _ = ctx.Session.Delete("openid_determined_email")
  427. _ = ctx.Session.Delete("openid_determined_username")
  428. _ = ctx.Session.Delete("twofaUid")
  429. _ = ctx.Session.Delete("twofaRemember")
  430. _ = ctx.Session.Delete("u2fChallenge")
  431. _ = ctx.Session.Delete("linkAccount")
  432. err := ctx.Session.Set("uid", u.ID)
  433. if err != nil {
  434. log.Error(fmt.Sprintf("Error setting session: %v", err))
  435. }
  436. err = ctx.Session.Set("uname", u.Name)
  437. if err != nil {
  438. log.Error(fmt.Sprintf("Error setting session: %v", err))
  439. }
  440. // Language setting of the user overwrites the one previously set
  441. // If the user does not have a locale set, we save the current one.
  442. if len(u.Language) == 0 {
  443. u.Language = ctx.Locale.Language()
  444. if err := models.UpdateUserCols(u, "language"); err != nil {
  445. log.Error(fmt.Sprintf("Error updating user language [user: %d, locale: %s]", u.ID, u.Language))
  446. return setting.AppSubURL + "/"
  447. }
  448. }
  449. ctx.SetCookie("lang", u.Language, nil, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  450. // Clear whatever CSRF has right now, force to generate a new one
  451. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  452. // Register last login
  453. u.SetLastLogin()
  454. if err := models.UpdateUserCols(u, "last_login_unix"); err != nil {
  455. ctx.ServerError("UpdateUserCols", err)
  456. return setting.AppSubURL + "/"
  457. }
  458. if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 && !util.IsExternalURL(redirectTo) {
  459. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  460. if obeyRedirect {
  461. ctx.RedirectToFirst(redirectTo)
  462. }
  463. return redirectTo
  464. }
  465. if obeyRedirect {
  466. ctx.Redirect(setting.AppSubURL + "/")
  467. }
  468. return setting.AppSubURL + "/"
  469. }
  470. // SignInOAuth handles the OAuth2 login buttons
  471. func SignInOAuth(ctx *context.Context) {
  472. provider := ctx.Params(":provider")
  473. loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider)
  474. if err != nil {
  475. ctx.ServerError("SignIn", err)
  476. return
  477. }
  478. // try to do a direct callback flow, so we don't authenticate the user again but use the valid accesstoken to get the user
  479. user, gothUser, err := oAuth2UserLoginCallback(loginSource, ctx.Req.Request, ctx.Resp)
  480. if err == nil && user != nil {
  481. // we got the user without going through the whole OAuth2 authentication flow again
  482. handleOAuth2SignIn(user, gothUser, ctx, err)
  483. return
  484. }
  485. err = oauth2.Auth(loginSource.Name, ctx.Req.Request, ctx.Resp)
  486. if err != nil {
  487. ctx.ServerError("SignIn", err)
  488. }
  489. // redirect is done in oauth2.Auth
  490. }
  491. // SignInOAuthCallback handles the callback from the given provider
  492. func SignInOAuthCallback(ctx *context.Context) {
  493. provider := ctx.Params(":provider")
  494. // first look if the provider is still active
  495. loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider)
  496. if err != nil {
  497. ctx.ServerError("SignIn", err)
  498. return
  499. }
  500. if loginSource == nil {
  501. ctx.ServerError("SignIn", errors.New("No valid provider found, check configured callback url in provider"))
  502. return
  503. }
  504. u, gothUser, err := oAuth2UserLoginCallback(loginSource, ctx.Req.Request, ctx.Resp)
  505. handleOAuth2SignIn(u, gothUser, ctx, err)
  506. }
  507. func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context, err error) {
  508. if err != nil {
  509. ctx.ServerError("UserSignIn", err)
  510. return
  511. }
  512. if u == nil {
  513. // no existing user is found, request attach or new account
  514. err = ctx.Session.Set("linkAccountGothUser", gothUser)
  515. if err != nil {
  516. log.Error(fmt.Sprintf("Error setting session: %v", err))
  517. }
  518. ctx.Redirect(setting.AppSubURL + "/user/link_account")
  519. return
  520. }
  521. // If this user is enrolled in 2FA, we can't sign the user in just yet.
  522. // Instead, redirect them to the 2FA authentication page.
  523. _, err = models.GetTwoFactorByUID(u.ID)
  524. if err != nil {
  525. if models.IsErrTwoFactorNotEnrolled(err) {
  526. err = ctx.Session.Set("uid", u.ID)
  527. if err != nil {
  528. log.Error(fmt.Sprintf("Error setting session: %v", err))
  529. }
  530. err = ctx.Session.Set("uname", u.Name)
  531. if err != nil {
  532. log.Error(fmt.Sprintf("Error setting session: %v", err))
  533. }
  534. // Clear whatever CSRF has right now, force to generate a new one
  535. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  536. // Register last login
  537. u.SetLastLogin()
  538. if err := models.UpdateUserCols(u, "last_login_unix"); err != nil {
  539. ctx.ServerError("UpdateUserCols", err)
  540. return
  541. }
  542. if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 {
  543. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  544. ctx.RedirectToFirst(redirectTo)
  545. return
  546. }
  547. ctx.Redirect(setting.AppSubURL + "/")
  548. } else {
  549. ctx.ServerError("UserSignIn", err)
  550. }
  551. return
  552. }
  553. // User needs to use 2FA, save data and redirect to 2FA page.
  554. err = ctx.Session.Set("twofaUid", u.ID)
  555. if err != nil {
  556. log.Error(fmt.Sprintf("Error setting session: %v", err))
  557. }
  558. err = ctx.Session.Set("twofaRemember", false)
  559. if err != nil {
  560. log.Error(fmt.Sprintf("Error setting session: %v", err))
  561. }
  562. // If U2F is enrolled -> Redirect to U2F instead
  563. regs, err := models.GetU2FRegistrationsByUID(u.ID)
  564. if err == nil && len(regs) > 0 {
  565. ctx.Redirect(setting.AppSubURL + "/user/u2f")
  566. return
  567. }
  568. ctx.Redirect(setting.AppSubURL + "/user/two_factor")
  569. }
  570. // OAuth2UserLoginCallback attempts to handle the callback from the OAuth2 provider and if successful
  571. // login the user
  572. func oAuth2UserLoginCallback(loginSource *models.LoginSource, request *http.Request, response http.ResponseWriter) (*models.User, goth.User, error) {
  573. gothUser, err := oauth2.ProviderCallback(loginSource.Name, request, response)
  574. if err != nil {
  575. return nil, goth.User{}, err
  576. }
  577. user := &models.User{
  578. LoginName: gothUser.UserID,
  579. LoginType: models.LoginOAuth2,
  580. LoginSource: loginSource.ID,
  581. }
  582. hasUser, err := models.GetUser(user)
  583. if err != nil {
  584. return nil, goth.User{}, err
  585. }
  586. if hasUser {
  587. return user, goth.User{}, nil
  588. }
  589. // search in external linked users
  590. externalLoginUser := &models.ExternalLoginUser{
  591. ExternalID: gothUser.UserID,
  592. LoginSourceID: loginSource.ID,
  593. }
  594. hasUser, err = models.GetExternalLogin(externalLoginUser)
  595. if err != nil {
  596. return nil, goth.User{}, err
  597. }
  598. if hasUser {
  599. user, err = models.GetUserByID(externalLoginUser.UserID)
  600. return user, goth.User{}, err
  601. }
  602. // no user found to login
  603. return nil, gothUser, nil
  604. }
  605. // LinkAccount shows the page where the user can decide to login or create a new account
  606. func LinkAccount(ctx *context.Context) {
  607. ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationCaptcha || setting.Service.AllowOnlyExternalRegistration
  608. ctx.Data["Title"] = ctx.Tr("link_account")
  609. ctx.Data["LinkAccountMode"] = true
  610. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha
  611. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  612. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  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. uname := gothUser.(goth.User).NickName
  625. email := gothUser.(goth.User).Email
  626. ctx.Data["user_name"] = uname
  627. ctx.Data["email"] = email
  628. if len(email) != 0 {
  629. u, err := models.GetUserByEmail(email)
  630. if err != nil && !models.IsErrUserNotExist(err) {
  631. ctx.ServerError("UserSignIn", err)
  632. return
  633. }
  634. if u != nil {
  635. ctx.Data["user_exists"] = true
  636. }
  637. } else if len(uname) != 0 {
  638. u, err := models.GetUserByName(uname)
  639. if err != nil && !models.IsErrUserNotExist(err) {
  640. ctx.ServerError("UserSignIn", err)
  641. return
  642. }
  643. if u != nil {
  644. ctx.Data["user_exists"] = true
  645. }
  646. }
  647. ctx.HTML(200, tplLinkAccount)
  648. }
  649. // LinkAccountPostSignIn handle the coupling of external account with another account using signIn
  650. func LinkAccountPostSignIn(ctx *context.Context, signInForm auth.SignInForm) {
  651. ctx.Data["DisablePassword"] = setting.Service.AllowOnlyExternalRegistration
  652. ctx.Data["Title"] = ctx.Tr("link_account")
  653. ctx.Data["LinkAccountMode"] = true
  654. ctx.Data["LinkAccountModeSignIn"] = true
  655. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha
  656. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  657. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  658. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  659. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
  660. ctx.Data["ShowRegistrationButton"] = false
  661. // use this to set the right link into the signIn and signUp templates in the link_account template
  662. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
  663. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"
  664. gothUser := ctx.Session.Get("linkAccountGothUser")
  665. if gothUser == nil {
  666. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  667. return
  668. }
  669. if ctx.HasError() {
  670. ctx.HTML(200, tplLinkAccount)
  671. return
  672. }
  673. u, err := models.UserSignIn(signInForm.UserName, signInForm.Password)
  674. if err != nil {
  675. if models.IsErrUserNotExist(err) {
  676. ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplLinkAccount, &signInForm)
  677. } else {
  678. ctx.ServerError("UserLinkAccount", err)
  679. }
  680. return
  681. }
  682. // If this user is enrolled in 2FA, we can't sign the user in just yet.
  683. // Instead, redirect them to the 2FA authentication page.
  684. _, err = models.GetTwoFactorByUID(u.ID)
  685. if err != nil {
  686. if models.IsErrTwoFactorNotEnrolled(err) {
  687. err = models.LinkAccountToUser(u, gothUser.(goth.User))
  688. if err != nil {
  689. ctx.ServerError("UserLinkAccount", err)
  690. } else {
  691. handleSignIn(ctx, u, signInForm.Remember)
  692. }
  693. } else {
  694. ctx.ServerError("UserLinkAccount", err)
  695. }
  696. return
  697. }
  698. // User needs to use 2FA, save data and redirect to 2FA page.
  699. err = ctx.Session.Set("twofaUid", u.ID)
  700. if err != nil {
  701. log.Error(fmt.Sprintf("Error setting session: %v", err))
  702. }
  703. err = ctx.Session.Set("twofaRemember", signInForm.Remember)
  704. if err != nil {
  705. log.Error(fmt.Sprintf("Error setting session: %v", err))
  706. }
  707. err = ctx.Session.Set("linkAccount", true)
  708. if err != nil {
  709. log.Error(fmt.Sprintf("Error setting session: %v", err))
  710. }
  711. // If U2F is enrolled -> Redirect to U2F instead
  712. regs, err := models.GetU2FRegistrationsByUID(u.ID)
  713. if err == nil && len(regs) > 0 {
  714. ctx.Redirect(setting.AppSubURL + "/user/u2f")
  715. return
  716. }
  717. ctx.Redirect(setting.AppSubURL + "/user/two_factor")
  718. }
  719. // LinkAccountPostRegister handle the creation of a new account for an external account using signUp
  720. func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterForm) {
  721. // TODO Make insecure passwords optional for local accounts also,
  722. // once email-based Second-Factor Auth is available
  723. ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationCaptcha || setting.Service.AllowOnlyExternalRegistration
  724. ctx.Data["Title"] = ctx.Tr("link_account")
  725. ctx.Data["LinkAccountMode"] = true
  726. ctx.Data["LinkAccountModeRegister"] = true
  727. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha
  728. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  729. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  730. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  731. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
  732. ctx.Data["ShowRegistrationButton"] = false
  733. // use this to set the right link into the signIn and signUp templates in the link_account template
  734. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
  735. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"
  736. gothUser := ctx.Session.Get("linkAccountGothUser")
  737. if gothUser == nil {
  738. ctx.ServerError("UserSignUp", errors.New("not in LinkAccount session"))
  739. return
  740. }
  741. if ctx.HasError() {
  742. ctx.HTML(200, tplLinkAccount)
  743. return
  744. }
  745. if setting.Service.DisableRegistration {
  746. ctx.Error(403)
  747. return
  748. }
  749. if setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha {
  750. var valid bool
  751. switch setting.Service.CaptchaType {
  752. case setting.ImageCaptcha:
  753. valid = cpt.VerifyReq(ctx.Req)
  754. case setting.ReCaptcha:
  755. valid, _ = recaptcha.Verify(form.GRecaptchaResponse)
  756. default:
  757. ctx.ServerError("Unknown Captcha Type", fmt.Errorf("Unknown Captcha Type: %s", setting.Service.CaptchaType))
  758. return
  759. }
  760. if !valid {
  761. ctx.Data["Err_Captcha"] = true
  762. ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplLinkAccount, &form)
  763. return
  764. }
  765. }
  766. if setting.Service.AllowOnlyExternalRegistration || !setting.Service.RequireExternalRegistrationPassword {
  767. // In models.User an empty password is classed as not set, so we set form.Password to empty.
  768. // Eventually the database should be changed to indicate "Second Factor"-enabled accounts
  769. // (accounts that do not introduce the security vulnerabilities of a password).
  770. // If a user decides to circumvent second-factor security, and purposefully create a password,
  771. // they can still do so using the "Recover Account" option.
  772. form.Password = ""
  773. } else {
  774. if (len(strings.TrimSpace(form.Password)) > 0 || len(strings.TrimSpace(form.Retype)) > 0) && form.Password != form.Retype {
  775. ctx.Data["Err_Password"] = true
  776. ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplLinkAccount, &form)
  777. return
  778. }
  779. if len(strings.TrimSpace(form.Password)) > 0 && len(form.Password) < setting.MinPasswordLength {
  780. ctx.Data["Err_Password"] = true
  781. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplLinkAccount, &form)
  782. return
  783. }
  784. }
  785. loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.(goth.User).Provider)
  786. if err != nil {
  787. ctx.ServerError("CreateUser", err)
  788. }
  789. u := &models.User{
  790. Name: form.UserName,
  791. Email: form.Email,
  792. Passwd: form.Password,
  793. IsActive: !setting.Service.RegisterEmailConfirm,
  794. LoginType: models.LoginOAuth2,
  795. LoginSource: loginSource.ID,
  796. LoginName: gothUser.(goth.User).UserID,
  797. }
  798. if err := models.CreateUser(u); err != nil {
  799. switch {
  800. case models.IsErrUserAlreadyExist(err):
  801. ctx.Data["Err_UserName"] = true
  802. ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplLinkAccount, &form)
  803. case models.IsErrEmailAlreadyUsed(err):
  804. ctx.Data["Err_Email"] = true
  805. ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplLinkAccount, &form)
  806. case models.IsErrNameReserved(err):
  807. ctx.Data["Err_UserName"] = true
  808. ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tplLinkAccount, &form)
  809. case models.IsErrNamePatternNotAllowed(err):
  810. ctx.Data["Err_UserName"] = true
  811. ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplLinkAccount, &form)
  812. default:
  813. ctx.ServerError("CreateUser", err)
  814. }
  815. return
  816. }
  817. log.Trace("Account created: %s", u.Name)
  818. // Auto-set admin for the only user.
  819. if models.CountUsers() == 1 {
  820. u.IsAdmin = true
  821. u.IsActive = true
  822. u.SetLastLogin()
  823. if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil {
  824. ctx.ServerError("UpdateUser", err)
  825. return
  826. }
  827. }
  828. // Send confirmation email
  829. if setting.Service.RegisterEmailConfirm && u.ID > 1 {
  830. mailer.SendActivateAccountMail(ctx.Locale, u)
  831. ctx.Data["IsSendRegisterMail"] = true
  832. ctx.Data["Email"] = u.Email
  833. ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
  834. ctx.HTML(200, TplActivate)
  835. if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
  836. log.Error("Set cache(MailResendLimit) fail: %v", err)
  837. }
  838. return
  839. }
  840. ctx.Redirect(setting.AppSubURL + "/user/login")
  841. }
  842. func handleSignOut(ctx *context.Context) {
  843. _ = ctx.Session.Delete("uid")
  844. _ = ctx.Session.Delete("uname")
  845. _ = ctx.Session.Delete("socialId")
  846. _ = ctx.Session.Delete("socialName")
  847. _ = ctx.Session.Delete("socialEmail")
  848. ctx.SetCookie(setting.CookieUserName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  849. ctx.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  850. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  851. ctx.SetCookie("lang", "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true) // Setting the lang cookie will trigger the middleware to reset the language ot previous state.
  852. }
  853. // SignOut sign out from login status
  854. func SignOut(ctx *context.Context) {
  855. handleSignOut(ctx)
  856. ctx.Redirect(setting.AppSubURL + "/")
  857. }
  858. // SignUp render the register page
  859. func SignUp(ctx *context.Context) {
  860. ctx.Data["Title"] = ctx.Tr("sign_up")
  861. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
  862. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
  863. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  864. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  865. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  866. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
  867. ctx.HTML(200, tplSignUp)
  868. }
  869. // SignUpPost response for sign up information submission
  870. func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterForm) {
  871. ctx.Data["Title"] = ctx.Tr("sign_up")
  872. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
  873. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
  874. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  875. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  876. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  877. //Permission denied if DisableRegistration or AllowOnlyExternalRegistration options are true
  878. if setting.Service.DisableRegistration {
  879. ctx.Error(403)
  880. return
  881. }
  882. if ctx.HasError() {
  883. ctx.HTML(200, tplSignUp)
  884. return
  885. }
  886. if setting.Service.EnableCaptcha {
  887. var valid bool
  888. switch setting.Service.CaptchaType {
  889. case setting.ImageCaptcha:
  890. valid = cpt.VerifyReq(ctx.Req)
  891. case setting.ReCaptcha:
  892. valid, _ = recaptcha.Verify(form.GRecaptchaResponse)
  893. default:
  894. ctx.ServerError("Unknown Captcha Type", fmt.Errorf("Unknown Captcha Type: %s", setting.Service.CaptchaType))
  895. return
  896. }
  897. if !valid {
  898. ctx.Data["Err_Captcha"] = true
  899. ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplSignUp, &form)
  900. return
  901. }
  902. }
  903. if !form.IsEmailDomainWhitelisted() {
  904. ctx.RenderWithErr(ctx.Tr("auth.email_domain_blacklisted"), tplSignUp, &form)
  905. return
  906. }
  907. if form.Password != form.Retype {
  908. ctx.Data["Err_Password"] = true
  909. ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplSignUp, &form)
  910. return
  911. }
  912. if len(form.Password) < setting.MinPasswordLength {
  913. ctx.Data["Err_Password"] = true
  914. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplSignUp, &form)
  915. return
  916. }
  917. u := &models.User{
  918. Name: form.UserName,
  919. Email: form.Email,
  920. Passwd: form.Password,
  921. IsActive: !setting.Service.RegisterEmailConfirm,
  922. }
  923. if err := models.CreateUser(u); err != nil {
  924. switch {
  925. case models.IsErrUserAlreadyExist(err):
  926. ctx.Data["Err_UserName"] = true
  927. ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplSignUp, &form)
  928. case models.IsErrEmailAlreadyUsed(err):
  929. ctx.Data["Err_Email"] = true
  930. ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignUp, &form)
  931. case models.IsErrNameReserved(err):
  932. ctx.Data["Err_UserName"] = true
  933. ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tplSignUp, &form)
  934. case models.IsErrNamePatternNotAllowed(err):
  935. ctx.Data["Err_UserName"] = true
  936. ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSignUp, &form)
  937. default:
  938. ctx.ServerError("CreateUser", err)
  939. }
  940. return
  941. }
  942. log.Trace("Account created: %s", u.Name)
  943. // Auto-set admin for the only user.
  944. if models.CountUsers() == 1 {
  945. u.IsAdmin = true
  946. u.IsActive = true
  947. u.SetLastLogin()
  948. if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil {
  949. ctx.ServerError("UpdateUser", err)
  950. return
  951. }
  952. }
  953. // Send confirmation email, no need for social account.
  954. if setting.Service.RegisterEmailConfirm && u.ID > 1 {
  955. mailer.SendActivateAccountMail(ctx.Locale, u)
  956. ctx.Data["IsSendRegisterMail"] = true
  957. ctx.Data["Email"] = u.Email
  958. ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
  959. ctx.HTML(200, TplActivate)
  960. if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
  961. log.Error("Set cache(MailResendLimit) fail: %v", err)
  962. }
  963. return
  964. }
  965. ctx.Flash.Success(ctx.Tr("auth.sign_up_successful"))
  966. handleSignInFull(ctx, u, false, true)
  967. }
  968. // Activate render activate user page
  969. func Activate(ctx *context.Context) {
  970. code := ctx.Query("code")
  971. if len(code) == 0 {
  972. ctx.Data["IsActivatePage"] = true
  973. if ctx.User.IsActive {
  974. ctx.Error(404)
  975. return
  976. }
  977. // Resend confirmation email.
  978. if setting.Service.RegisterEmailConfirm {
  979. if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) {
  980. ctx.Data["ResendLimited"] = true
  981. } else {
  982. ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
  983. mailer.SendActivateAccountMail(ctx.Locale, ctx.User)
  984. if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
  985. log.Error("Set cache(MailResendLimit) fail: %v", err)
  986. }
  987. }
  988. } else {
  989. ctx.Data["ServiceNotEnabled"] = true
  990. }
  991. ctx.HTML(200, TplActivate)
  992. return
  993. }
  994. // Verify code.
  995. if user := models.VerifyUserActiveCode(code); user != nil {
  996. user.IsActive = true
  997. var err error
  998. if user.Rands, err = models.GetUserSalt(); err != nil {
  999. ctx.ServerError("UpdateUser", err)
  1000. return
  1001. }
  1002. if err := models.UpdateUserCols(user, "is_active", "rands"); err != nil {
  1003. if models.IsErrUserNotExist(err) {
  1004. ctx.Error(404)
  1005. } else {
  1006. ctx.ServerError("UpdateUser", err)
  1007. }
  1008. return
  1009. }
  1010. log.Trace("User activated: %s", user.Name)
  1011. err = ctx.Session.Set("uid", user.ID)
  1012. if err != nil {
  1013. log.Error(fmt.Sprintf("Error setting session: %v", err))
  1014. }
  1015. err = ctx.Session.Set("uname", user.Name)
  1016. if err != nil {
  1017. log.Error(fmt.Sprintf("Error setting session: %v", err))
  1018. }
  1019. ctx.Flash.Success(ctx.Tr("auth.account_activated"))
  1020. ctx.Redirect(setting.AppSubURL + "/")
  1021. return
  1022. }
  1023. ctx.Data["IsActivateFailed"] = true
  1024. ctx.HTML(200, TplActivate)
  1025. }
  1026. // ActivateEmail render the activate email page
  1027. func ActivateEmail(ctx *context.Context) {
  1028. code := ctx.Query("code")
  1029. emailStr := ctx.Query("email")
  1030. // Verify code.
  1031. if email := models.VerifyActiveEmailCode(code, emailStr); email != nil {
  1032. if err := email.Activate(); err != nil {
  1033. ctx.ServerError("ActivateEmail", err)
  1034. }
  1035. log.Trace("Email activated: %s", email.Email)
  1036. ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
  1037. }
  1038. ctx.Redirect(setting.AppSubURL + "/user/settings/email")
  1039. }
  1040. // ForgotPasswd render the forget pasword page
  1041. func ForgotPasswd(ctx *context.Context) {
  1042. ctx.Data["Title"] = ctx.Tr("auth.forgot_password_title")
  1043. if setting.MailService == nil {
  1044. ctx.Data["IsResetDisable"] = true
  1045. ctx.HTML(200, tplForgotPassword)
  1046. return
  1047. }
  1048. email := ctx.Query("email")
  1049. ctx.Data["Email"] = email
  1050. ctx.Data["IsResetRequest"] = true
  1051. ctx.HTML(200, tplForgotPassword)
  1052. }
  1053. // ForgotPasswdPost response for forget password request
  1054. func ForgotPasswdPost(ctx *context.Context) {
  1055. ctx.Data["Title"] = ctx.Tr("auth.forgot_password_title")
  1056. if setting.MailService == nil {
  1057. ctx.NotFound("ForgotPasswdPost", nil)
  1058. return
  1059. }
  1060. ctx.Data["IsResetRequest"] = true
  1061. email := ctx.Query("email")
  1062. ctx.Data["Email"] = email
  1063. u, err := models.GetUserByEmail(email)
  1064. if err != nil {
  1065. if models.IsErrUserNotExist(err) {
  1066. ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
  1067. ctx.Data["IsResetSent"] = true
  1068. ctx.HTML(200, tplForgotPassword)
  1069. return
  1070. }
  1071. ctx.ServerError("user.ResetPasswd(check existence)", err)
  1072. return
  1073. }
  1074. if !u.IsLocal() && !u.IsOAuth2() {
  1075. ctx.Data["Err_Email"] = true
  1076. ctx.RenderWithErr(ctx.Tr("auth.non_local_account"), tplForgotPassword, nil)
  1077. return
  1078. }
  1079. if ctx.Cache.IsExist("MailResendLimit_" + u.LowerName) {
  1080. ctx.Data["ResendLimited"] = true
  1081. ctx.HTML(200, tplForgotPassword)
  1082. return
  1083. }
  1084. mailer.SendResetPasswordMail(ctx.Locale, u)
  1085. if err = ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
  1086. log.Error("Set cache(MailResendLimit) fail: %v", err)
  1087. }
  1088. ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
  1089. ctx.Data["IsResetSent"] = true
  1090. ctx.HTML(200, tplForgotPassword)
  1091. }
  1092. func commonResetPassword(ctx *context.Context) *models.User {
  1093. code := ctx.Query("code")
  1094. ctx.Data["Title"] = ctx.Tr("auth.reset_password")
  1095. ctx.Data["Code"] = code
  1096. if nil != ctx.User {
  1097. ctx.Data["user_signed_in"] = true
  1098. }
  1099. if len(code) == 0 {
  1100. ctx.Flash.Error(ctx.Tr("auth.invalid_code"))
  1101. return nil
  1102. }
  1103. // Fail early, don't frustrate the user
  1104. u := models.VerifyUserActiveCode(code)
  1105. if u == nil {
  1106. ctx.Flash.Error(ctx.Tr("auth.invalid_code"))
  1107. return nil
  1108. }
  1109. // Show the user that they are affecting the account that they intended to
  1110. ctx.Data["user_email"] = u.Email
  1111. if nil != ctx.User && u.ID != ctx.User.ID {
  1112. ctx.Flash.Error(ctx.Tr("auth.reset_password_wrong_user", ctx.User.Email, u.Email))
  1113. return nil
  1114. }
  1115. return u
  1116. }
  1117. // ResetPasswd render the account recovery page
  1118. func ResetPasswd(ctx *context.Context) {
  1119. ctx.Data["IsResetForm"] = true
  1120. commonResetPassword(ctx)
  1121. ctx.HTML(200, tplResetPassword)
  1122. }
  1123. // ResetPasswdPost response from account recovery request
  1124. func ResetPasswdPost(ctx *context.Context) {
  1125. u := commonResetPassword(ctx)
  1126. if u == nil {
  1127. // Flash error has been set
  1128. ctx.HTML(200, tplResetPassword)
  1129. return
  1130. }
  1131. // Validate password length.
  1132. passwd := ctx.Query("password")
  1133. if len(passwd) < setting.MinPasswordLength {
  1134. ctx.Data["IsResetForm"] = true
  1135. ctx.Data["Err_Password"] = true
  1136. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplResetPassword, nil)
  1137. return
  1138. }
  1139. var err error
  1140. if u.Rands, err = models.GetUserSalt(); err != nil {
  1141. ctx.ServerError("UpdateUser", err)
  1142. return
  1143. }
  1144. if u.Salt, err = models.GetUserSalt(); err != nil {
  1145. ctx.ServerError("UpdateUser", err)
  1146. return
  1147. }
  1148. u.HashPassword(passwd)
  1149. u.MustChangePassword = false
  1150. if err := models.UpdateUserCols(u, "must_change_password", "passwd", "rands", "salt"); err != nil {
  1151. ctx.ServerError("UpdateUser", err)
  1152. return
  1153. }
  1154. log.Trace("User password reset: %s", u.Name)
  1155. ctx.Data["IsResetFailed"] = true
  1156. remember := len(ctx.Query("remember")) != 0
  1157. handleSignInFull(ctx, u, remember, true)
  1158. }
  1159. // MustChangePassword renders the page to change a user's password
  1160. func MustChangePassword(ctx *context.Context) {
  1161. ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
  1162. ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password"
  1163. ctx.HTML(200, tplMustChangePassword)
  1164. }
  1165. // MustChangePasswordPost response for updating a user's password after his/her
  1166. // account was created by an admin
  1167. func MustChangePasswordPost(ctx *context.Context, cpt *captcha.Captcha, form auth.MustChangePasswordForm) {
  1168. ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
  1169. ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password"
  1170. if ctx.HasError() {
  1171. ctx.HTML(200, tplMustChangePassword)
  1172. return
  1173. }
  1174. u := ctx.User
  1175. // Make sure only requests for users who are eligible to change their password via
  1176. // this method passes through
  1177. if !u.MustChangePassword {
  1178. ctx.ServerError("MustUpdatePassword", errors.New("cannot update password.. Please visit the settings page"))
  1179. return
  1180. }
  1181. if form.Password != form.Retype {
  1182. ctx.Data["Err_Password"] = true
  1183. ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplMustChangePassword, &form)
  1184. return
  1185. }
  1186. if len(form.Password) < setting.MinPasswordLength {
  1187. ctx.Data["Err_Password"] = true
  1188. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplMustChangePassword, &form)
  1189. return
  1190. }
  1191. var err error
  1192. if u.Salt, err = models.GetUserSalt(); err != nil {
  1193. ctx.ServerError("UpdateUser", err)
  1194. return
  1195. }
  1196. u.HashPassword(form.Password)
  1197. u.MustChangePassword = false
  1198. if err := models.UpdateUserCols(u, "must_change_password", "passwd", "salt"); err != nil {
  1199. ctx.ServerError("UpdateUser", err)
  1200. return
  1201. }
  1202. ctx.Flash.Success(ctx.Tr("settings.change_password_success"))
  1203. log.Trace("User updated password: %s", u.Name)
  1204. if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 && !util.IsExternalURL(redirectTo) {
  1205. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL)
  1206. ctx.RedirectToFirst(redirectTo)
  1207. return
  1208. }
  1209. ctx.Redirect(setting.AppSubURL + "/")
  1210. }