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 51 kB

3 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
Add single sign-on support via SSPI on Windows (#8463) * Add single sign-on support via SSPI on Windows * Ensure plugins implement interface * Ensure plugins implement interface * Move functions used only by the SSPI auth method to sspi_windows.go * Field SSPISeparatorReplacement of AuthenticationForm should not be required via binding, as binding will insist the field is non-empty even if another login type is selected * Fix breaking of oauth authentication on download links. Do not create new session with SSPI authentication on download links. * Update documentation for the new 'SPNEGO with SSPI' login source * Mention in documentation that ROOT_URL should contain the FQDN of the server * Make sure that Contexter is not checking for active login sources when the ORM engine is not initialized (eg. when installing) * Always initialize and free SSO methods, even if they are not enabled, as a method can be activated while the app is running (from Authentication sources) * Add option in SSPIConfig for removing of domains from logon names * Update helper text for StripDomainNames option * Make sure handleSignIn() is called after a new user object is created by SSPI auth method * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Only make a query to the DB to check if SSPI is enabled on handlers that need that information for templates * Remove code duplication * Log errors in ActiveLoginSources Co-Authored-By: Lauris BH <lauris@nix.lv> * Revert suffix of randomly generated E-mails for Reverse proxy authentication Co-Authored-By: Lauris BH <lauris@nix.lv> * Revert unneeded white-space change in template Co-Authored-By: Lauris BH <lauris@nix.lv> * Add copyright comments at the top of new files * Use loopback name for randomly generated emails * Add locale tag for the SSPISeparatorReplacement field with proper casing * Revert casing of SSPISeparatorReplacement field in locale file, moving it up, next to other form fields * Update docs/content/doc/features/authentication.en-us.md Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Remove Priority() method and define the order in which SSO auth methods should be executed in one place * Log authenticated username only if it's not empty * Rephrase helper text for automatic creation of users * Return error if more than one active SSPI auth source is found * Change newUser() function to return error, letting caller log/handle the error * Move isPublicResource, isPublicPage and handleSignIn functions outside SSPI auth method to allow other SSO methods to reuse them if needed * Refactor initialization of the list containing SSO auth methods * Validate SSPI settings on POST * Change SSPI to only perform authentication on its own login page, API paths and download links. Leave Toggle middleware to redirect non authenticated users to login page * Make 'Default language' in SSPI config empty, unless changed by admin * Show error if admin tries to add a second authentication source of type SSPI * Simplify declaration of global variable * Rebuild gitgraph.js on Linux * Make sure config values containing only whitespace are not accepted
5 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
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
Add single sign-on support via SSPI on Windows (#8463) * Add single sign-on support via SSPI on Windows * Ensure plugins implement interface * Ensure plugins implement interface * Move functions used only by the SSPI auth method to sspi_windows.go * Field SSPISeparatorReplacement of AuthenticationForm should not be required via binding, as binding will insist the field is non-empty even if another login type is selected * Fix breaking of oauth authentication on download links. Do not create new session with SSPI authentication on download links. * Update documentation for the new 'SPNEGO with SSPI' login source * Mention in documentation that ROOT_URL should contain the FQDN of the server * Make sure that Contexter is not checking for active login sources when the ORM engine is not initialized (eg. when installing) * Always initialize and free SSO methods, even if they are not enabled, as a method can be activated while the app is running (from Authentication sources) * Add option in SSPIConfig for removing of domains from logon names * Update helper text for StripDomainNames option * Make sure handleSignIn() is called after a new user object is created by SSPI auth method * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Only make a query to the DB to check if SSPI is enabled on handlers that need that information for templates * Remove code duplication * Log errors in ActiveLoginSources Co-Authored-By: Lauris BH <lauris@nix.lv> * Revert suffix of randomly generated E-mails for Reverse proxy authentication Co-Authored-By: Lauris BH <lauris@nix.lv> * Revert unneeded white-space change in template Co-Authored-By: Lauris BH <lauris@nix.lv> * Add copyright comments at the top of new files * Use loopback name for randomly generated emails * Add locale tag for the SSPISeparatorReplacement field with proper casing * Revert casing of SSPISeparatorReplacement field in locale file, moving it up, next to other form fields * Update docs/content/doc/features/authentication.en-us.md Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Remove Priority() method and define the order in which SSO auth methods should be executed in one place * Log authenticated username only if it's not empty * Rephrase helper text for automatic creation of users * Return error if more than one active SSPI auth source is found * Change newUser() function to return error, letting caller log/handle the error * Move isPublicResource, isPublicPage and handleSignIn functions outside SSPI auth method to allow other SSO methods to reuse them if needed * Refactor initialization of the list containing SSO auth methods * Validate SSPI settings on POST * Change SSPI to only perform authentication on its own login page, API paths and download links. Leave Toggle middleware to redirect non authenticated users to login page * Make 'Default language' in SSPI config empty, unless changed by admin * Show error if admin tries to add a second authentication source of type SSPI * Simplify declaration of global variable * Rebuild gitgraph.js on Linux * Make sure config values containing only whitespace are not accepted
5 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
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
3 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
3 years ago
3 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
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
3 years ago
3 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  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/routers/repo"
  12. "code.gitea.io/gitea/models"
  13. "code.gitea.io/gitea/modules/auth"
  14. "code.gitea.io/gitea/modules/auth/oauth2"
  15. "code.gitea.io/gitea/modules/base"
  16. "code.gitea.io/gitea/modules/context"
  17. "code.gitea.io/gitea/modules/eventsource"
  18. "code.gitea.io/gitea/modules/log"
  19. "code.gitea.io/gitea/modules/password"
  20. "code.gitea.io/gitea/modules/recaptcha"
  21. "code.gitea.io/gitea/modules/setting"
  22. "code.gitea.io/gitea/modules/timeutil"
  23. "code.gitea.io/gitea/modules/util"
  24. "code.gitea.io/gitea/services/externalaccount"
  25. "code.gitea.io/gitea/services/mailer"
  26. "gitea.com/macaron/captcha"
  27. "github.com/markbates/goth"
  28. "github.com/tstranex/u2f"
  29. )
  30. const (
  31. // tplMustChangePassword template for updating a user's password
  32. tplMustChangePassword = "user/auth/change_passwd"
  33. // tplSignIn template for sign in page
  34. tplSignIn base.TplName = "user/auth/signin"
  35. // tplSignIn template for sign in page
  36. tplSignInCloudBrain base.TplName = "user/auth/signin_cloud_brain"
  37. // tplSignUp template path for sign up page
  38. tplSignUp base.TplName = "user/auth/signup"
  39. // TplActivate template path for activate user
  40. TplActivate base.TplName = "user/auth/activate"
  41. tplForgotPassword base.TplName = "user/auth/forgot_passwd"
  42. tplResetPassword base.TplName = "user/auth/reset_passwd"
  43. tplTwofa base.TplName = "user/auth/twofa"
  44. tplTwofaScratch base.TplName = "user/auth/twofa_scratch"
  45. tplLinkAccount base.TplName = "user/auth/link_account"
  46. tplU2F base.TplName = "user/auth/u2f"
  47. )
  48. // AutoSignIn reads cookie and try to auto-login.
  49. func AutoSignIn(ctx *context.Context) (bool, error) {
  50. if !models.HasEngine {
  51. return false, nil
  52. }
  53. uname := ctx.GetCookie(setting.CookieUserName)
  54. if len(uname) == 0 {
  55. return false, nil
  56. }
  57. isSucceed := false
  58. defer func() {
  59. if !isSucceed {
  60. log.Trace("auto-login cookie cleared: %s", uname)
  61. ctx.SetCookie(setting.CookieUserName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  62. ctx.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  63. }
  64. }()
  65. u, err := models.GetUserByName(uname)
  66. if err != nil {
  67. if !models.IsErrUserNotExist(err) {
  68. return false, fmt.Errorf("GetUserByName: %v", err)
  69. }
  70. return false, nil
  71. }
  72. if val, ok := ctx.GetSuperSecureCookie(
  73. base.EncodeMD5(u.Rands+u.Passwd), setting.CookieRememberName); !ok || val != u.Name {
  74. return false, nil
  75. }
  76. isSucceed = true
  77. // Set session IDs
  78. if err := ctx.Session.Set("uid", u.ID); err != nil {
  79. return false, err
  80. }
  81. if err := ctx.Session.Set("uname", u.Name); err != nil {
  82. return false, err
  83. }
  84. if err := ctx.Session.Release(); err != nil {
  85. return false, err
  86. }
  87. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  88. return true, nil
  89. }
  90. func checkAutoLogin(ctx *context.Context) bool {
  91. // Check auto-login.
  92. isSucceed, err := AutoSignIn(ctx)
  93. if err != nil {
  94. ctx.ServerError("AutoSignIn", err)
  95. return true
  96. }
  97. redirectTo := ctx.Query("redirect_to")
  98. if len(redirectTo) > 0 {
  99. ctx.SetCookie("redirect_to", redirectTo, 0, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  100. } else {
  101. redirectTo = ctx.GetCookie("redirect_to")
  102. }
  103. if isSucceed {
  104. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  105. ctx.RedirectToFirst(redirectTo, setting.AppSubURL+string(setting.LandingPageURL))
  106. return true
  107. }
  108. return false
  109. }
  110. // SignIn render sign in page
  111. func SignIn(ctx *context.Context) {
  112. ctx.Data["Title"] = ctx.Tr("sign_in")
  113. // Check auto-login.
  114. if checkAutoLogin(ctx) {
  115. return
  116. }
  117. orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers()
  118. if err != nil {
  119. ctx.ServerError("UserSignIn", err)
  120. return
  121. }
  122. ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names
  123. ctx.Data["OAuth2Providers"] = oauth2Providers
  124. ctx.Data["Title"] = ctx.Tr("sign_in")
  125. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login"
  126. ctx.Data["PageIsSignIn"] = true
  127. ctx.Data["PageIsLogin"] = true
  128. ctx.Data["EnableSSPI"] = models.IsSSPIEnabled()
  129. ctx.Data["EnableCloudBrain"] = true
  130. ctx.HTML(200, tplSignIn)
  131. }
  132. // SignInCloudBrain render sign in page
  133. func SignInCloudBrain(ctx *context.Context) {
  134. ctx.Data["Title"] = ctx.Tr("sign_in")
  135. // Check auto-login.
  136. if checkAutoLogin(ctx) {
  137. return
  138. }
  139. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login"
  140. ctx.Data["PageIsSignIn"] = true
  141. ctx.Data["PageIsCloudBrainLogin"] = true
  142. ctx.Data["EnableCloudBrain"] = true
  143. ctx.HTML(200, tplSignInCloudBrain)
  144. }
  145. // SignInPost response for sign in request
  146. func SignInPost(ctx *context.Context, form auth.SignInForm) {
  147. ctx.Data["Title"] = ctx.Tr("sign_in")
  148. orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers()
  149. if err != nil {
  150. ctx.ServerError("UserSignIn", err)
  151. return
  152. }
  153. ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names
  154. ctx.Data["OAuth2Providers"] = oauth2Providers
  155. ctx.Data["Title"] = ctx.Tr("sign_in")
  156. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login"
  157. ctx.Data["PageIsSignIn"] = true
  158. ctx.Data["PageIsLogin"] = true
  159. ctx.Data["EnableSSPI"] = models.IsSSPIEnabled()
  160. if ctx.HasError() {
  161. ctx.HTML(200, tplSignIn)
  162. return
  163. }
  164. u, err := models.UserSignIn(form.UserName, form.Password)
  165. if err != nil {
  166. if models.IsErrUserNotExist(err) {
  167. ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form)
  168. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  169. } else if models.IsErrEmailAlreadyUsed(err) {
  170. ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignIn, &form)
  171. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  172. } else if models.IsErrUserProhibitLogin(err) {
  173. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  174. ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
  175. ctx.HTML(200, "user/auth/prohibit_login")
  176. } else if models.IsErrUserInactive(err) {
  177. if setting.Service.RegisterEmailConfirm {
  178. ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
  179. ctx.HTML(200, TplActivate)
  180. } else {
  181. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  182. ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
  183. ctx.HTML(200, "user/auth/prohibit_login")
  184. }
  185. } else {
  186. ctx.ServerError("UserSignIn", err)
  187. }
  188. return
  189. }
  190. // If this user is enrolled in 2FA, we can't sign the user in just yet.
  191. // Instead, redirect them to the 2FA authentication page.
  192. _, err = models.GetTwoFactorByUID(u.ID)
  193. if err != nil {
  194. if models.IsErrTwoFactorNotEnrolled(err) {
  195. handleSignIn(ctx, u, form.Remember)
  196. } else {
  197. ctx.ServerError("UserSignIn", err)
  198. }
  199. return
  200. }
  201. // User needs to use 2FA, save data and redirect to 2FA page.
  202. if err := ctx.Session.Set("twofaUid", u.ID); err != nil {
  203. ctx.ServerError("UserSignIn: Unable to set twofaUid in session", err)
  204. return
  205. }
  206. if err := ctx.Session.Set("twofaRemember", form.Remember); err != nil {
  207. ctx.ServerError("UserSignIn: Unable to set twofaRemember in session", err)
  208. return
  209. }
  210. if err := ctx.Session.Release(); err != nil {
  211. ctx.ServerError("UserSignIn: Unable to save session", err)
  212. return
  213. }
  214. regs, err := models.GetU2FRegistrationsByUID(u.ID)
  215. if err == nil && len(regs) > 0 {
  216. ctx.Redirect(setting.AppSubURL + "/user/u2f")
  217. return
  218. }
  219. ctx.Redirect(setting.AppSubURL + "/user/two_factor")
  220. }
  221. // TwoFactor shows the user a two-factor authentication page.
  222. func TwoFactor(ctx *context.Context) {
  223. ctx.Data["Title"] = ctx.Tr("twofa")
  224. // Check auto-login.
  225. if checkAutoLogin(ctx) {
  226. return
  227. }
  228. // Ensure user is in a 2FA session.
  229. if ctx.Session.Get("twofaUid") == nil {
  230. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  231. return
  232. }
  233. ctx.HTML(200, tplTwofa)
  234. }
  235. // TwoFactorPost validates a user's two-factor authentication token.
  236. func TwoFactorPost(ctx *context.Context, form auth.TwoFactorAuthForm) {
  237. ctx.Data["Title"] = ctx.Tr("twofa")
  238. // Ensure user is in a 2FA session.
  239. idSess := ctx.Session.Get("twofaUid")
  240. if idSess == nil {
  241. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  242. return
  243. }
  244. id := idSess.(int64)
  245. twofa, err := models.GetTwoFactorByUID(id)
  246. if err != nil {
  247. ctx.ServerError("UserSignIn", err)
  248. return
  249. }
  250. // Validate the passcode with the stored TOTP secret.
  251. ok, err := twofa.ValidateTOTP(form.Passcode)
  252. if err != nil {
  253. ctx.ServerError("UserSignIn", err)
  254. return
  255. }
  256. if ok && twofa.LastUsedPasscode != form.Passcode {
  257. remember := ctx.Session.Get("twofaRemember").(bool)
  258. u, err := models.GetUserByID(id)
  259. if err != nil {
  260. ctx.ServerError("UserSignIn", err)
  261. return
  262. }
  263. if ctx.Session.Get("linkAccount") != nil {
  264. gothUser := ctx.Session.Get("linkAccountGothUser")
  265. if gothUser == nil {
  266. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  267. return
  268. }
  269. err = externalaccount.LinkAccountToUser(u, gothUser.(goth.User))
  270. if err != nil {
  271. ctx.ServerError("UserSignIn", err)
  272. return
  273. }
  274. }
  275. twofa.LastUsedPasscode = form.Passcode
  276. if err = models.UpdateTwoFactor(twofa); err != nil {
  277. ctx.ServerError("UserSignIn", err)
  278. return
  279. }
  280. handleSignIn(ctx, u, remember)
  281. return
  282. }
  283. ctx.RenderWithErr(ctx.Tr("auth.twofa_passcode_incorrect"), tplTwofa, auth.TwoFactorAuthForm{})
  284. }
  285. // TwoFactorScratch shows the scratch code form for two-factor authentication.
  286. func TwoFactorScratch(ctx *context.Context) {
  287. ctx.Data["Title"] = ctx.Tr("twofa_scratch")
  288. // Check auto-login.
  289. if checkAutoLogin(ctx) {
  290. return
  291. }
  292. // Ensure user is in a 2FA session.
  293. if ctx.Session.Get("twofaUid") == nil {
  294. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  295. return
  296. }
  297. ctx.HTML(200, tplTwofaScratch)
  298. }
  299. // TwoFactorScratchPost validates and invalidates a user's two-factor scratch token.
  300. func TwoFactorScratchPost(ctx *context.Context, form auth.TwoFactorScratchAuthForm) {
  301. ctx.Data["Title"] = ctx.Tr("twofa_scratch")
  302. // Ensure user is in a 2FA session.
  303. idSess := ctx.Session.Get("twofaUid")
  304. if idSess == nil {
  305. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  306. return
  307. }
  308. id := idSess.(int64)
  309. twofa, err := models.GetTwoFactorByUID(id)
  310. if err != nil {
  311. ctx.ServerError("UserSignIn", err)
  312. return
  313. }
  314. // Validate the passcode with the stored TOTP secret.
  315. if twofa.VerifyScratchToken(form.Token) {
  316. // Invalidate the scratch token.
  317. _, err = twofa.GenerateScratchToken()
  318. if err != nil {
  319. ctx.ServerError("UserSignIn", err)
  320. return
  321. }
  322. if err = models.UpdateTwoFactor(twofa); err != nil {
  323. ctx.ServerError("UserSignIn", err)
  324. return
  325. }
  326. remember := ctx.Session.Get("twofaRemember").(bool)
  327. u, err := models.GetUserByID(id)
  328. if err != nil {
  329. ctx.ServerError("UserSignIn", err)
  330. return
  331. }
  332. handleSignInFull(ctx, u, remember, false)
  333. ctx.Flash.Info(ctx.Tr("auth.twofa_scratch_used"))
  334. ctx.Redirect(setting.AppSubURL + "/user/settings/security")
  335. return
  336. }
  337. ctx.RenderWithErr(ctx.Tr("auth.twofa_scratch_token_incorrect"), tplTwofaScratch, auth.TwoFactorScratchAuthForm{})
  338. }
  339. // U2F shows the U2F login page
  340. func U2F(ctx *context.Context) {
  341. ctx.Data["Title"] = ctx.Tr("twofa")
  342. ctx.Data["RequireU2F"] = true
  343. // Check auto-login.
  344. if checkAutoLogin(ctx) {
  345. return
  346. }
  347. // Ensure user is in a 2FA session.
  348. if ctx.Session.Get("twofaUid") == nil {
  349. ctx.ServerError("UserSignIn", errors.New("not in U2F session"))
  350. return
  351. }
  352. ctx.HTML(200, tplU2F)
  353. }
  354. // U2FChallenge submits a sign challenge to the browser
  355. func U2FChallenge(ctx *context.Context) {
  356. // Ensure user is in a U2F session.
  357. idSess := ctx.Session.Get("twofaUid")
  358. if idSess == nil {
  359. ctx.ServerError("UserSignIn", errors.New("not in U2F session"))
  360. return
  361. }
  362. id := idSess.(int64)
  363. regs, err := models.GetU2FRegistrationsByUID(id)
  364. if err != nil {
  365. ctx.ServerError("UserSignIn", err)
  366. return
  367. }
  368. if len(regs) == 0 {
  369. ctx.ServerError("UserSignIn", errors.New("no device registered"))
  370. return
  371. }
  372. challenge, err := u2f.NewChallenge(setting.U2F.AppID, setting.U2F.TrustedFacets)
  373. if err != nil {
  374. ctx.ServerError("u2f.NewChallenge", err)
  375. return
  376. }
  377. if err := ctx.Session.Set("u2fChallenge", challenge); err != nil {
  378. ctx.ServerError("UserSignIn: unable to set u2fChallenge in session", err)
  379. return
  380. }
  381. if err := ctx.Session.Release(); err != nil {
  382. ctx.ServerError("UserSignIn: unable to store session", err)
  383. }
  384. ctx.JSON(200, challenge.SignRequest(regs.ToRegistrations()))
  385. }
  386. // U2FSign authenticates the user by signResp
  387. func U2FSign(ctx *context.Context, signResp u2f.SignResponse) {
  388. challSess := ctx.Session.Get("u2fChallenge")
  389. idSess := ctx.Session.Get("twofaUid")
  390. if challSess == nil || idSess == nil {
  391. ctx.ServerError("UserSignIn", errors.New("not in U2F session"))
  392. return
  393. }
  394. challenge := challSess.(*u2f.Challenge)
  395. id := idSess.(int64)
  396. regs, err := models.GetU2FRegistrationsByUID(id)
  397. if err != nil {
  398. ctx.ServerError("UserSignIn", err)
  399. return
  400. }
  401. for _, reg := range regs {
  402. r, err := reg.Parse()
  403. if err != nil {
  404. log.Fatal("parsing u2f registration: %v", err)
  405. continue
  406. }
  407. newCounter, authErr := r.Authenticate(signResp, *challenge, reg.Counter)
  408. if authErr == nil {
  409. reg.Counter = newCounter
  410. user, err := models.GetUserByID(id)
  411. if err != nil {
  412. ctx.ServerError("UserSignIn", err)
  413. return
  414. }
  415. remember := ctx.Session.Get("twofaRemember").(bool)
  416. if err := reg.UpdateCounter(); err != nil {
  417. ctx.ServerError("UserSignIn", err)
  418. return
  419. }
  420. if ctx.Session.Get("linkAccount") != nil {
  421. gothUser := ctx.Session.Get("linkAccountGothUser")
  422. if gothUser == nil {
  423. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  424. return
  425. }
  426. err = externalaccount.LinkAccountToUser(user, gothUser.(goth.User))
  427. if err != nil {
  428. ctx.ServerError("UserSignIn", err)
  429. return
  430. }
  431. }
  432. redirect := handleSignInFull(ctx, user, remember, false)
  433. if redirect == "" {
  434. redirect = setting.AppSubURL + "/"
  435. }
  436. ctx.PlainText(200, []byte(redirect))
  437. return
  438. }
  439. }
  440. ctx.Error(401)
  441. }
  442. // This handles the final part of the sign-in process of the user.
  443. func handleSignIn(ctx *context.Context, u *models.User, remember bool) {
  444. handleSignInFull(ctx, u, remember, true)
  445. }
  446. func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyRedirect bool) string {
  447. if remember {
  448. days := 86400 * setting.LogInRememberDays
  449. ctx.SetCookie(setting.CookieUserName, u.Name, days, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  450. ctx.SetSuperSecureCookie(base.EncodeMD5(u.Rands+u.Passwd),
  451. setting.CookieRememberName, u.Name, days, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  452. }
  453. _ = ctx.Session.Delete("openid_verified_uri")
  454. _ = ctx.Session.Delete("openid_signin_remember")
  455. _ = ctx.Session.Delete("openid_determined_email")
  456. _ = ctx.Session.Delete("openid_determined_username")
  457. _ = ctx.Session.Delete("twofaUid")
  458. _ = ctx.Session.Delete("twofaRemember")
  459. _ = ctx.Session.Delete("u2fChallenge")
  460. _ = ctx.Session.Delete("linkAccount")
  461. if err := ctx.Session.Set("uid", u.ID); err != nil {
  462. log.Error("Error setting uid %d in session: %v", u.ID, err)
  463. }
  464. if err := ctx.Session.Set("uname", u.Name); err != nil {
  465. log.Error("Error setting uname %s session: %v", u.Name, err)
  466. }
  467. if err := ctx.Session.Release(); err != nil {
  468. log.Error("Unable to store session: %v", err)
  469. }
  470. // If the user does not have a locale set, we save the current one.
  471. if len(u.Language) == 0 {
  472. if len(ctx.GetCookie("lang")) != 0 {
  473. u.Language = ctx.GetCookie("lang")
  474. } else {
  475. u.Language = ctx.Locale.Language()
  476. }
  477. if err := models.UpdateUserCols(u, "language"); err != nil {
  478. log.Error(fmt.Sprintf("Error updating user language [user: %d, locale: %s]", u.ID, u.Language))
  479. return setting.AppSubURL + "/"
  480. }
  481. } else {
  482. // Language setting of the user use the one previously set
  483. if len(ctx.GetCookie("lang")) != 0 {
  484. u.Language = ctx.GetCookie("lang")
  485. }
  486. }
  487. ctx.SetCookie("lang", u.Language, nil, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  488. // Clear whatever CSRF has right now, force to generate a new one
  489. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  490. // Register last login
  491. u.SetLastLogin()
  492. if err := models.UpdateUserCols(u, "last_login_unix"); err != nil {
  493. ctx.ServerError("UpdateUserCols", err)
  494. return setting.AppSubURL + "/"
  495. }
  496. if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 && !util.IsExternalURL(redirectTo) {
  497. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  498. if obeyRedirect {
  499. ctx.RedirectToFirst(redirectTo)
  500. }
  501. return redirectTo
  502. }
  503. if obeyRedirect {
  504. ctx.Redirect(setting.AppSubURL + "/")
  505. }
  506. return setting.AppSubURL + "/"
  507. }
  508. // SignInOAuth handles the OAuth2 login buttons
  509. func SignInOAuth(ctx *context.Context) {
  510. provider := ctx.Params(":provider")
  511. loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider)
  512. if err != nil {
  513. ctx.ServerError("SignIn", err)
  514. return
  515. }
  516. // try to do a direct callback flow, so we don't authenticate the user again but use the valid accesstoken to get the user
  517. user, gothUser, err := oAuth2UserLoginCallback(loginSource, ctx.Req.Request, ctx.Resp)
  518. if err == nil && user != nil {
  519. // we got the user without going through the whole OAuth2 authentication flow again
  520. handleOAuth2SignIn(user, gothUser, ctx, err)
  521. return
  522. }
  523. err = oauth2.Auth(loginSource.Name, ctx.Req.Request, ctx.Resp)
  524. if err != nil {
  525. ctx.ServerError("SignIn", err)
  526. }
  527. // redirect is done in oauth2.Auth
  528. }
  529. // SignInOAuthCallback handles the callback from the given provider
  530. func SignInOAuthCallback(ctx *context.Context) {
  531. provider := ctx.Params(":provider")
  532. // first look if the provider is still active
  533. loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider)
  534. if err != nil {
  535. ctx.ServerError("SignIn", err)
  536. return
  537. }
  538. if loginSource == nil {
  539. ctx.ServerError("SignIn", errors.New("No valid provider found, check configured callback url in provider"))
  540. return
  541. }
  542. u, gothUser, err := oAuth2UserLoginCallback(loginSource, ctx.Req.Request, ctx.Resp)
  543. handleOAuth2SignIn(u, gothUser, ctx, err)
  544. }
  545. func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context, err error) {
  546. if err != nil {
  547. ctx.ServerError("UserSignIn", err)
  548. return
  549. }
  550. if u == nil {
  551. // no existing user is found, request attach or new account
  552. if err := ctx.Session.Set("linkAccountGothUser", gothUser); err != nil {
  553. log.Error("Error setting linkAccountGothUser in session: %v", err)
  554. }
  555. if err := ctx.Session.Release(); err != nil {
  556. log.Error("Error storing session: %v", err)
  557. }
  558. ctx.Redirect(setting.AppSubURL + "/user/link_account")
  559. return
  560. }
  561. // If this user is enrolled in 2FA, we can't sign the user in just yet.
  562. // Instead, redirect them to the 2FA authentication page.
  563. _, err = models.GetTwoFactorByUID(u.ID)
  564. if err != nil {
  565. if !models.IsErrTwoFactorNotEnrolled(err) {
  566. ctx.ServerError("UserSignIn", err)
  567. return
  568. }
  569. if err := ctx.Session.Set("uid", u.ID); err != nil {
  570. log.Error("Error setting uid in session: %v", err)
  571. }
  572. if err := ctx.Session.Set("uname", u.Name); err != nil {
  573. log.Error("Error setting uname in session: %v", err)
  574. }
  575. if err := ctx.Session.Release(); err != nil {
  576. log.Error("Error storing session: %v", err)
  577. }
  578. // Clear whatever CSRF has right now, force to generate a new one
  579. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  580. // Register last login
  581. u.SetLastLogin()
  582. if err := models.UpdateUserCols(u, "last_login_unix"); err != nil {
  583. ctx.ServerError("UpdateUserCols", err)
  584. return
  585. }
  586. // update external user information
  587. if err := models.UpdateExternalUser(u, gothUser); err != nil {
  588. log.Error("UpdateExternalUser failed: %v", err)
  589. }
  590. if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 {
  591. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  592. ctx.RedirectToFirst(redirectTo)
  593. return
  594. }
  595. ctx.Redirect(setting.AppSubURL + "/")
  596. return
  597. }
  598. // User needs to use 2FA, save data and redirect to 2FA page.
  599. if err := ctx.Session.Set("twofaUid", u.ID); err != nil {
  600. log.Error("Error setting twofaUid in session: %v", err)
  601. }
  602. if err := ctx.Session.Set("twofaRemember", false); err != nil {
  603. log.Error("Error setting twofaRemember in session: %v", err)
  604. }
  605. if err := ctx.Session.Release(); err != nil {
  606. log.Error("Error storing session: %v", err)
  607. }
  608. // If U2F is enrolled -> Redirect to U2F instead
  609. regs, err := models.GetU2FRegistrationsByUID(u.ID)
  610. if err == nil && len(regs) > 0 {
  611. ctx.Redirect(setting.AppSubURL + "/user/u2f")
  612. return
  613. }
  614. ctx.Redirect(setting.AppSubURL + "/user/two_factor")
  615. }
  616. // OAuth2UserLoginCallback attempts to handle the callback from the OAuth2 provider and if successful
  617. // login the user
  618. func oAuth2UserLoginCallback(loginSource *models.LoginSource, request *http.Request, response http.ResponseWriter) (*models.User, goth.User, error) {
  619. gothUser, err := oauth2.ProviderCallback(loginSource.Name, request, response)
  620. if err != nil {
  621. if err.Error() == "securecookie: the value is too long" {
  622. log.Error("OAuth2 Provider %s returned too long a token. Current max: %d. Either increase the [OAuth2] MAX_TOKEN_LENGTH or reduce the information returned from the OAuth2 provider", loginSource.Name, setting.OAuth2.MaxTokenLength)
  623. err = fmt.Errorf("OAuth2 Provider %s returned too long a token. Current max: %d. Either increase the [OAuth2] MAX_TOKEN_LENGTH or reduce the information returned from the OAuth2 provider", loginSource.Name, setting.OAuth2.MaxTokenLength)
  624. }
  625. return nil, goth.User{}, err
  626. }
  627. user := &models.User{
  628. LoginName: gothUser.UserID,
  629. LoginType: models.LoginOAuth2,
  630. LoginSource: loginSource.ID,
  631. }
  632. hasUser, err := models.GetUser(user)
  633. if err != nil {
  634. return nil, goth.User{}, err
  635. }
  636. if hasUser {
  637. return user, gothUser, nil
  638. }
  639. // search in external linked users
  640. externalLoginUser := &models.ExternalLoginUser{
  641. ExternalID: gothUser.UserID,
  642. LoginSourceID: loginSource.ID,
  643. }
  644. hasUser, err = models.GetExternalLogin(externalLoginUser)
  645. if err != nil {
  646. return nil, goth.User{}, err
  647. }
  648. if hasUser {
  649. user, err = models.GetUserByID(externalLoginUser.UserID)
  650. return user, gothUser, err
  651. }
  652. // no user found to login
  653. return nil, gothUser, nil
  654. }
  655. // LinkAccount shows the page where the user can decide to login or create a new account
  656. func LinkAccount(ctx *context.Context) {
  657. ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration
  658. ctx.Data["Title"] = ctx.Tr("link_account")
  659. ctx.Data["LinkAccountMode"] = true
  660. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha
  661. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  662. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  663. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  664. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
  665. ctx.Data["ShowRegistrationButton"] = false
  666. // use this to set the right link into the signIn and signUp templates in the link_account template
  667. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
  668. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"
  669. gothUser := ctx.Session.Get("linkAccountGothUser")
  670. if gothUser == nil {
  671. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  672. return
  673. }
  674. uname := gothUser.(goth.User).NickName
  675. email := gothUser.(goth.User).Email
  676. ctx.Data["user_name"] = uname
  677. ctx.Data["email"] = email
  678. if len(email) != 0 {
  679. u, err := models.GetUserByEmail(email)
  680. if err != nil && !models.IsErrUserNotExist(err) {
  681. ctx.ServerError("UserSignIn", err)
  682. return
  683. }
  684. if u != nil {
  685. ctx.Data["user_exists"] = true
  686. }
  687. } else if len(uname) != 0 {
  688. u, err := models.GetUserByName(uname)
  689. if err != nil && !models.IsErrUserNotExist(err) {
  690. ctx.ServerError("UserSignIn", err)
  691. return
  692. }
  693. if u != nil {
  694. ctx.Data["user_exists"] = true
  695. }
  696. }
  697. ctx.HTML(200, tplLinkAccount)
  698. }
  699. // LinkAccountPostSignIn handle the coupling of external account with another account using signIn
  700. func LinkAccountPostSignIn(ctx *context.Context, signInForm auth.SignInForm) {
  701. ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration
  702. ctx.Data["Title"] = ctx.Tr("link_account")
  703. ctx.Data["LinkAccountMode"] = true
  704. ctx.Data["LinkAccountModeSignIn"] = true
  705. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha
  706. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  707. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  708. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  709. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
  710. ctx.Data["ShowRegistrationButton"] = false
  711. // use this to set the right link into the signIn and signUp templates in the link_account template
  712. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
  713. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"
  714. gothUser := ctx.Session.Get("linkAccountGothUser")
  715. if gothUser == nil {
  716. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  717. return
  718. }
  719. if ctx.HasError() {
  720. ctx.HTML(200, tplLinkAccount)
  721. return
  722. }
  723. u, err := models.UserSignIn(signInForm.UserName, signInForm.Password)
  724. if err != nil {
  725. if models.IsErrUserNotExist(err) {
  726. ctx.Data["user_exists"] = true
  727. ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplLinkAccount, &signInForm)
  728. } else {
  729. ctx.ServerError("UserLinkAccount", err)
  730. }
  731. return
  732. }
  733. // If this user is enrolled in 2FA, we can't sign the user in just yet.
  734. // Instead, redirect them to the 2FA authentication page.
  735. _, err = models.GetTwoFactorByUID(u.ID)
  736. if err != nil {
  737. if !models.IsErrTwoFactorNotEnrolled(err) {
  738. ctx.ServerError("UserLinkAccount", err)
  739. return
  740. }
  741. err = externalaccount.LinkAccountToUser(u, gothUser.(goth.User))
  742. if err != nil {
  743. ctx.ServerError("UserLinkAccount", err)
  744. return
  745. }
  746. handleSignIn(ctx, u, signInForm.Remember)
  747. return
  748. }
  749. // User needs to use 2FA, save data and redirect to 2FA page.
  750. if err := ctx.Session.Set("twofaUid", u.ID); err != nil {
  751. log.Error("Error setting twofaUid in session: %v", err)
  752. }
  753. if err := ctx.Session.Set("twofaRemember", signInForm.Remember); err != nil {
  754. log.Error("Error setting twofaRemember in session: %v", err)
  755. }
  756. if err := ctx.Session.Set("linkAccount", true); err != nil {
  757. log.Error("Error setting linkAccount in session: %v", err)
  758. }
  759. if err := ctx.Session.Release(); err != nil {
  760. log.Error("Error storing session: %v", err)
  761. }
  762. // If U2F is enrolled -> Redirect to U2F instead
  763. regs, err := models.GetU2FRegistrationsByUID(u.ID)
  764. if err == nil && len(regs) > 0 {
  765. ctx.Redirect(setting.AppSubURL + "/user/u2f")
  766. return
  767. }
  768. ctx.Redirect(setting.AppSubURL + "/user/two_factor")
  769. }
  770. // LinkAccountPostRegister handle the creation of a new account for an external account using signUp
  771. func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterForm) {
  772. // TODO Make insecure passwords optional for local accounts also,
  773. // once email-based Second-Factor Auth is available
  774. ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration
  775. ctx.Data["Title"] = ctx.Tr("link_account")
  776. ctx.Data["LinkAccountMode"] = true
  777. ctx.Data["LinkAccountModeRegister"] = true
  778. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha
  779. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  780. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  781. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  782. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
  783. ctx.Data["ShowRegistrationButton"] = false
  784. // use this to set the right link into the signIn and signUp templates in the link_account template
  785. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
  786. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"
  787. gothUser := ctx.Session.Get("linkAccountGothUser")
  788. if gothUser == nil {
  789. ctx.ServerError("UserSignUp", errors.New("not in LinkAccount session"))
  790. return
  791. }
  792. if ctx.HasError() {
  793. ctx.HTML(200, tplLinkAccount)
  794. return
  795. }
  796. if setting.Service.DisableRegistration {
  797. ctx.Error(403)
  798. return
  799. }
  800. if setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha {
  801. var valid bool
  802. switch setting.Service.CaptchaType {
  803. case setting.ImageCaptcha:
  804. valid = cpt.VerifyReq(ctx.Req)
  805. case setting.ReCaptcha:
  806. valid, _ = recaptcha.Verify(form.GRecaptchaResponse)
  807. default:
  808. ctx.ServerError("Unknown Captcha Type", fmt.Errorf("Unknown Captcha Type: %s", setting.Service.CaptchaType))
  809. return
  810. }
  811. if !valid {
  812. ctx.Data["Err_Captcha"] = true
  813. ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplLinkAccount, &form)
  814. return
  815. }
  816. }
  817. if setting.Service.AllowOnlyExternalRegistration || !setting.Service.RequireExternalRegistrationPassword {
  818. // In models.User an empty password is classed as not set, so we set form.Password to empty.
  819. // Eventually the database should be changed to indicate "Second Factor"-enabled accounts
  820. // (accounts that do not introduce the security vulnerabilities of a password).
  821. // If a user decides to circumvent second-factor security, and purposefully create a password,
  822. // they can still do so using the "Recover Account" option.
  823. form.Password = ""
  824. } else {
  825. if (len(strings.TrimSpace(form.Password)) > 0 || len(strings.TrimSpace(form.Retype)) > 0) && form.Password != form.Retype {
  826. ctx.Data["Err_Password"] = true
  827. ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplLinkAccount, &form)
  828. return
  829. }
  830. if len(strings.TrimSpace(form.Password)) > 0 && len(form.Password) < setting.MinPasswordLength {
  831. ctx.Data["Err_Password"] = true
  832. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplLinkAccount, &form)
  833. return
  834. }
  835. }
  836. loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.(goth.User).Provider)
  837. if err != nil {
  838. ctx.ServerError("CreateUser", err)
  839. }
  840. u := &models.User{
  841. Name: form.UserName,
  842. Email: form.Email,
  843. Passwd: form.Password,
  844. IsActive: !setting.Service.RegisterEmailConfirm,
  845. LoginType: models.LoginOAuth2,
  846. LoginSource: loginSource.ID,
  847. LoginName: gothUser.(goth.User).UserID,
  848. }
  849. //nolint: dupl
  850. if err := models.CreateUser(u); err != nil {
  851. switch {
  852. case models.IsErrUserAlreadyExist(err):
  853. ctx.Data["Err_UserName"] = true
  854. ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplLinkAccount, &form)
  855. case models.IsErrEmailAlreadyUsed(err):
  856. ctx.Data["Err_Email"] = true
  857. ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplLinkAccount, &form)
  858. case models.IsErrNameReserved(err):
  859. ctx.Data["Err_UserName"] = true
  860. ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tplLinkAccount, &form)
  861. case models.IsErrNamePatternNotAllowed(err):
  862. ctx.Data["Err_UserName"] = true
  863. ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplLinkAccount, &form)
  864. case models.IsErrNameCharsNotAllowed(err):
  865. ctx.Data["Err_UserName"] = true
  866. ctx.RenderWithErr(ctx.Tr("user.form.name_chars_not_allowed", err.(models.ErrNameCharsNotAllowed).Name), tplLinkAccount, &form)
  867. default:
  868. ctx.ServerError("CreateUser", err)
  869. }
  870. return
  871. }
  872. log.Trace("Account created: %s", u.Name)
  873. // Auto-set admin for the only user.
  874. if models.CountUsers() == 1 {
  875. u.IsAdmin = true
  876. u.IsActive = true
  877. u.SetLastLogin()
  878. if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil {
  879. ctx.ServerError("UpdateUser", err)
  880. return
  881. }
  882. }
  883. // update external user information
  884. if err := models.UpdateExternalUser(u, gothUser.(goth.User)); err != nil {
  885. log.Error("UpdateExternalUser failed: %v", err)
  886. }
  887. // Send confirmation email
  888. if setting.Service.RegisterEmailConfirm && u.ID > 1 {
  889. mailer.SendActivateAccountMail(ctx.Locale, u)
  890. ctx.Data["IsSendRegisterMail"] = true
  891. ctx.Data["Email"] = u.Email
  892. ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
  893. ctx.HTML(200, TplActivate)
  894. if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
  895. log.Error("Set cache(MailResendLimit) fail: %v", err)
  896. }
  897. return
  898. }
  899. ctx.Redirect(setting.AppSubURL + "/user/login")
  900. }
  901. // HandleSignOut resets the session and sets the cookies
  902. func HandleSignOut(ctx *context.Context) {
  903. _ = ctx.Session.Flush()
  904. _ = ctx.Session.Destroy(ctx.Context)
  905. ctx.SetCookie(setting.CookieUserName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  906. ctx.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  907. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  908. 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.
  909. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL) // logout default should set redirect to to default
  910. }
  911. // SignOut sign out from login status
  912. func SignOut(ctx *context.Context) {
  913. if ctx.User != nil {
  914. eventsource.GetManager().SendMessageBlocking(ctx.User.ID, &eventsource.Event{
  915. Name: "logout",
  916. Data: ctx.Session.ID(),
  917. })
  918. }
  919. HandleSignOut(ctx)
  920. go repo.StopJobsByUserID(ctx.User.ID)
  921. ctx.Redirect(setting.AppSubURL + "/")
  922. }
  923. // SignUp render the register page
  924. func SignUp(ctx *context.Context) {
  925. ctx.Data["Title"] = ctx.Tr("sign_up")
  926. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
  927. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
  928. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  929. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  930. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  931. ctx.Data["PageIsSignUp"] = true
  932. //Show Disabled Registration message if DisableRegistration or AllowOnlyExternalRegistration options are true
  933. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration || setting.Service.AllowOnlyExternalRegistration
  934. ctx.HTML(200, tplSignUp)
  935. }
  936. // SignUpPost response for sign up information submission
  937. func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterForm) {
  938. ctx.Data["Title"] = ctx.Tr("sign_up")
  939. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
  940. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
  941. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  942. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  943. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  944. ctx.Data["PageIsSignUp"] = true
  945. //Permission denied if DisableRegistration or AllowOnlyExternalRegistration options are true
  946. if setting.Service.DisableRegistration || setting.Service.AllowOnlyExternalRegistration {
  947. ctx.Error(403)
  948. return
  949. }
  950. if ctx.HasError() {
  951. ctx.HTML(200, tplSignUp)
  952. return
  953. }
  954. if setting.Service.EnableCaptcha {
  955. var valid bool
  956. switch setting.Service.CaptchaType {
  957. case setting.ImageCaptcha:
  958. valid = cpt.VerifyReq(ctx.Req)
  959. case setting.ReCaptcha:
  960. valid, _ = recaptcha.Verify(form.GRecaptchaResponse)
  961. default:
  962. ctx.ServerError("Unknown Captcha Type", fmt.Errorf("Unknown Captcha Type: %s", setting.Service.CaptchaType))
  963. return
  964. }
  965. if !valid {
  966. ctx.Data["Err_Captcha"] = true
  967. ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplSignUp, &form)
  968. return
  969. }
  970. }
  971. if !form.IsEmailDomainWhitelisted() {
  972. ctx.RenderWithErr(ctx.Tr("auth.email_domain_blacklisted"), tplSignUp, &form)
  973. return
  974. }
  975. if form.Password != form.Retype {
  976. ctx.Data["Err_Password"] = true
  977. ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplSignUp, &form)
  978. return
  979. }
  980. if len(form.Password) < setting.MinPasswordLength {
  981. ctx.Data["Err_Password"] = true
  982. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplSignUp, &form)
  983. return
  984. }
  985. if !password.IsComplexEnough(form.Password) {
  986. ctx.Data["Err_Password"] = true
  987. ctx.RenderWithErr(password.BuildComplexityError(ctx), tplSignUp, &form)
  988. return
  989. }
  990. u := &models.User{
  991. Name: form.UserName,
  992. Email: form.Email,
  993. Passwd: form.Password,
  994. IsActive: !setting.Service.RegisterEmailConfirm,
  995. }
  996. if err := models.CreateUser(u); err != nil {
  997. switch {
  998. case models.IsErrUserAlreadyExist(err):
  999. ctx.Data["Err_UserName"] = true
  1000. ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplSignUp, &form)
  1001. case models.IsErrEmailAlreadyUsed(err):
  1002. ctx.Data["Err_Email"] = true
  1003. ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignUp, &form)
  1004. case models.IsErrNameReserved(err):
  1005. ctx.Data["Err_UserName"] = true
  1006. ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tplSignUp, &form)
  1007. case models.IsErrNamePatternNotAllowed(err):
  1008. ctx.Data["Err_UserName"] = true
  1009. ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSignUp, &form)
  1010. default:
  1011. ctx.ServerError("CreateUser", err)
  1012. }
  1013. return
  1014. }
  1015. log.Trace("Account created: %s", u.Name, ctx.Data["MsgID"])
  1016. err := models.AddEmailAddress(&models.EmailAddress{
  1017. UID: u.ID,
  1018. Email: form.Email,
  1019. IsActivated: !setting.Service.RegisterEmailConfirm,
  1020. })
  1021. if err != nil {
  1022. log.Error("AddEmailAddress failed:%v", err.Error(), ctx.Data["MsgID"])
  1023. ctx.ServerError("AddEmailAddress", err)
  1024. return
  1025. }
  1026. // Auto-set admin for the only user.
  1027. if models.CountUsers() == 1 {
  1028. u.IsAdmin = true
  1029. u.IsActive = true
  1030. u.SetLastLogin()
  1031. if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil {
  1032. ctx.ServerError("UpdateUser", err)
  1033. return
  1034. }
  1035. }
  1036. // Send confirmation email, no need for social account.
  1037. if setting.Service.RegisterEmailConfirm && u.ID > 1 {
  1038. mailer.SendActivateAccountMail(ctx.Locale, u)
  1039. ctx.Data["IsSendRegisterMail"] = true
  1040. ctx.Data["Email"] = u.Email
  1041. ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
  1042. ctx.HTML(200, TplActivate)
  1043. if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
  1044. log.Error("Set cache(MailResendLimit) fail: %v", err)
  1045. }
  1046. return
  1047. }
  1048. ctx.Flash.Success(ctx.Tr("auth.sign_up_successful"))
  1049. handleSignInFull(ctx, u, false, true)
  1050. }
  1051. // Activate render activate user page
  1052. func Activate(ctx *context.Context) {
  1053. code := ctx.Query("code")
  1054. if len(code) == 0 {
  1055. ctx.Data["IsActivatePage"] = true
  1056. if ctx.User.IsActive {
  1057. ctx.Error(404)
  1058. return
  1059. }
  1060. // Resend confirmation email.
  1061. if setting.Service.RegisterEmailConfirm {
  1062. if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) {
  1063. ctx.Data["ResendLimited"] = true
  1064. } else {
  1065. ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
  1066. mailer.SendActivateAccountMail(ctx.Locale, ctx.User)
  1067. if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
  1068. log.Error("Set cache(MailResendLimit) fail: %v", err)
  1069. }
  1070. }
  1071. } else {
  1072. ctx.Data["ServiceNotEnabled"] = true
  1073. }
  1074. ctx.HTML(200, TplActivate)
  1075. return
  1076. }
  1077. // Verify code.
  1078. if user := models.VerifyUserActiveCode(code); user != nil {
  1079. user.IsActive = true
  1080. var err error
  1081. if user.Rands, err = models.GetUserSalt(); err != nil {
  1082. ctx.ServerError("UpdateUser", err)
  1083. return
  1084. }
  1085. if err := models.UpdateUserCols(user, "is_active", "rands"); err != nil {
  1086. if models.IsErrUserNotExist(err) {
  1087. ctx.Error(404)
  1088. } else {
  1089. ctx.ServerError("UpdateUser", err)
  1090. }
  1091. return
  1092. }
  1093. log.Trace("User activated: %s", user.Name)
  1094. if err := ctx.Session.Set("uid", user.ID); err != nil {
  1095. log.Error(fmt.Sprintf("Error setting uid in session: %v", err))
  1096. }
  1097. if err := ctx.Session.Set("uname", user.Name); err != nil {
  1098. log.Error(fmt.Sprintf("Error setting uname in session: %v", err))
  1099. }
  1100. if err := ctx.Session.Release(); err != nil {
  1101. log.Error("Error storing session: %v", err)
  1102. }
  1103. email, err := models.GetEmailAddressByIDAndEmail(user.ID, user.Email)
  1104. if err != nil || email == nil{
  1105. log.Error("GetEmailAddressByIDAndEmail failed", ctx.Data["MsgID"])
  1106. } else {
  1107. if err := email.Activate(); err != nil {
  1108. log.Error("Activate failed: %v", err, ctx.Data["MsgID"])
  1109. }
  1110. }
  1111. ctx.Flash.Success(ctx.Tr("auth.account_activated"))
  1112. ctx.Redirect(setting.AppSubURL + "/")
  1113. return
  1114. }
  1115. ctx.Data["IsActivateFailed"] = true
  1116. ctx.HTML(200, TplActivate)
  1117. }
  1118. // ActivateEmail render the activate email page
  1119. func ActivateEmail(ctx *context.Context) {
  1120. code := ctx.Query("code")
  1121. emailStr := ctx.Query("email")
  1122. // Verify code.
  1123. if email := models.VerifyActiveEmailCode(code, emailStr); email != nil {
  1124. if err := email.Activate(); err != nil {
  1125. ctx.ServerError("ActivateEmail", err)
  1126. }
  1127. log.Trace("Email activated: %s", email.Email)
  1128. ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
  1129. if u, err := models.GetUserByID(email.UID); err != nil {
  1130. log.Warn("GetUserByID: %d", email.UID)
  1131. } else {
  1132. // Allow user to validate more emails
  1133. _ = ctx.Cache.Delete("MailResendLimit_" + u.LowerName)
  1134. }
  1135. }
  1136. // FIXME: e-mail verification does not require the user to be logged in,
  1137. // so this could be redirecting to the login page.
  1138. // Should users be logged in automatically here? (consider 2FA requirements, etc.)
  1139. ctx.Redirect(setting.AppSubURL + "/user/settings/account")
  1140. }
  1141. // ForgotPasswd render the forget pasword page
  1142. func ForgotPasswd(ctx *context.Context) {
  1143. ctx.Data["Title"] = ctx.Tr("auth.forgot_password_title")
  1144. if setting.MailService == nil {
  1145. ctx.Data["IsResetDisable"] = true
  1146. ctx.HTML(200, tplForgotPassword)
  1147. return
  1148. }
  1149. email := ctx.Query("email")
  1150. ctx.Data["Email"] = email
  1151. ctx.Data["IsResetRequest"] = true
  1152. ctx.HTML(200, tplForgotPassword)
  1153. }
  1154. // ForgotPasswdPost response for forget password request
  1155. func ForgotPasswdPost(ctx *context.Context) {
  1156. ctx.Data["Title"] = ctx.Tr("auth.forgot_password_title")
  1157. if setting.MailService == nil {
  1158. ctx.NotFound("ForgotPasswdPost", nil)
  1159. return
  1160. }
  1161. ctx.Data["IsResetRequest"] = true
  1162. email := ctx.Query("email")
  1163. ctx.Data["Email"] = email
  1164. u, err := models.GetUserByEmail(email)
  1165. if err != nil {
  1166. if models.IsErrUserNotExist(err) {
  1167. ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
  1168. ctx.Data["IsResetSent"] = true
  1169. ctx.HTML(200, tplForgotPassword)
  1170. return
  1171. }
  1172. ctx.ServerError("user.ResetPasswd(check existence)", err)
  1173. return
  1174. }
  1175. if !u.IsLocal() && !u.IsOAuth2() {
  1176. ctx.Data["Err_Email"] = true
  1177. ctx.RenderWithErr(ctx.Tr("auth.non_local_account"), tplForgotPassword, nil)
  1178. return
  1179. }
  1180. if ctx.Cache.IsExist("MailResendLimit_" + u.LowerName) {
  1181. ctx.Data["ResendLimited"] = true
  1182. ctx.HTML(200, tplForgotPassword)
  1183. return
  1184. }
  1185. mailer.SendResetPasswordMail(ctx.Locale, u)
  1186. if err = ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
  1187. log.Error("Set cache(MailResendLimit) fail: %v", err)
  1188. }
  1189. ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
  1190. ctx.Data["IsResetSent"] = true
  1191. ctx.HTML(200, tplForgotPassword)
  1192. }
  1193. func commonResetPassword(ctx *context.Context) (*models.User, *models.TwoFactor) {
  1194. code := ctx.Query("code")
  1195. ctx.Data["Title"] = ctx.Tr("auth.reset_password")
  1196. ctx.Data["Code"] = code
  1197. if nil != ctx.User {
  1198. ctx.Data["user_signed_in"] = true
  1199. }
  1200. if len(code) == 0 {
  1201. ctx.Flash.Error(ctx.Tr("auth.invalid_code"))
  1202. return nil, nil
  1203. }
  1204. // Fail early, don't frustrate the user
  1205. u := models.VerifyUserActiveCode(code)
  1206. if u == nil {
  1207. ctx.Flash.Error(ctx.Tr("auth.invalid_code"))
  1208. return nil, nil
  1209. }
  1210. twofa, err := models.GetTwoFactorByUID(u.ID)
  1211. if err != nil {
  1212. if !models.IsErrTwoFactorNotEnrolled(err) {
  1213. ctx.Error(http.StatusInternalServerError, "CommonResetPassword", err.Error())
  1214. return nil, nil
  1215. }
  1216. } else {
  1217. ctx.Data["has_two_factor"] = true
  1218. ctx.Data["scratch_code"] = ctx.QueryBool("scratch_code")
  1219. }
  1220. // Show the user that they are affecting the account that they intended to
  1221. ctx.Data["user_email"] = u.Email
  1222. if nil != ctx.User && u.ID != ctx.User.ID {
  1223. ctx.Flash.Error(ctx.Tr("auth.reset_password_wrong_user", ctx.User.Email, u.Email))
  1224. return nil, nil
  1225. }
  1226. return u, twofa
  1227. }
  1228. // ResetPasswd render the account recovery page
  1229. func ResetPasswd(ctx *context.Context) {
  1230. ctx.Data["IsResetForm"] = true
  1231. commonResetPassword(ctx)
  1232. if ctx.Written() {
  1233. return
  1234. }
  1235. ctx.HTML(200, tplResetPassword)
  1236. }
  1237. // ResetPasswdPost response from account recovery request
  1238. func ResetPasswdPost(ctx *context.Context) {
  1239. u, twofa := commonResetPassword(ctx)
  1240. if ctx.Written() {
  1241. return
  1242. }
  1243. if u == nil {
  1244. // Flash error has been set
  1245. ctx.HTML(200, tplResetPassword)
  1246. return
  1247. }
  1248. // Validate password length.
  1249. passwd := ctx.Query("password")
  1250. if len(passwd) < setting.MinPasswordLength {
  1251. ctx.Data["IsResetForm"] = true
  1252. ctx.Data["Err_Password"] = true
  1253. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplResetPassword, nil)
  1254. return
  1255. } else if !password.IsComplexEnough(passwd) {
  1256. ctx.Data["IsResetForm"] = true
  1257. ctx.Data["Err_Password"] = true
  1258. ctx.RenderWithErr(password.BuildComplexityError(ctx), tplResetPassword, nil)
  1259. return
  1260. }
  1261. // Handle two-factor
  1262. regenerateScratchToken := false
  1263. if twofa != nil {
  1264. if ctx.QueryBool("scratch_code") {
  1265. if !twofa.VerifyScratchToken(ctx.Query("token")) {
  1266. ctx.Data["IsResetForm"] = true
  1267. ctx.Data["Err_Token"] = true
  1268. ctx.RenderWithErr(ctx.Tr("auth.twofa_scratch_token_incorrect"), tplResetPassword, nil)
  1269. return
  1270. }
  1271. regenerateScratchToken = true
  1272. } else {
  1273. passcode := ctx.Query("passcode")
  1274. ok, err := twofa.ValidateTOTP(passcode)
  1275. if err != nil {
  1276. ctx.Error(http.StatusInternalServerError, "ValidateTOTP", err.Error())
  1277. return
  1278. }
  1279. if !ok || twofa.LastUsedPasscode == passcode {
  1280. ctx.Data["IsResetForm"] = true
  1281. ctx.Data["Err_Passcode"] = true
  1282. ctx.RenderWithErr(ctx.Tr("auth.twofa_passcode_incorrect"), tplResetPassword, nil)
  1283. return
  1284. }
  1285. twofa.LastUsedPasscode = passcode
  1286. if err = models.UpdateTwoFactor(twofa); err != nil {
  1287. ctx.ServerError("ResetPasswdPost: UpdateTwoFactor", err)
  1288. return
  1289. }
  1290. }
  1291. }
  1292. var err error
  1293. if u.Rands, err = models.GetUserSalt(); err != nil {
  1294. ctx.ServerError("UpdateUser", err)
  1295. return
  1296. }
  1297. if u.Salt, err = models.GetUserSalt(); err != nil {
  1298. ctx.ServerError("UpdateUser", err)
  1299. return
  1300. }
  1301. u.HashPassword(passwd)
  1302. u.MustChangePassword = false
  1303. if err := models.UpdateUserCols(u, "must_change_password", "passwd", "rands", "salt"); err != nil {
  1304. ctx.ServerError("UpdateUser", err)
  1305. return
  1306. }
  1307. log.Trace("User password reset: %s", u.Name)
  1308. ctx.Data["IsResetFailed"] = true
  1309. remember := len(ctx.Query("remember")) != 0
  1310. if regenerateScratchToken {
  1311. // Invalidate the scratch token.
  1312. _, err = twofa.GenerateScratchToken()
  1313. if err != nil {
  1314. ctx.ServerError("UserSignIn", err)
  1315. return
  1316. }
  1317. if err = models.UpdateTwoFactor(twofa); err != nil {
  1318. ctx.ServerError("UserSignIn", err)
  1319. return
  1320. }
  1321. handleSignInFull(ctx, u, remember, false)
  1322. ctx.Flash.Info(ctx.Tr("auth.twofa_scratch_used"))
  1323. ctx.Redirect(setting.AppSubURL + "/user/settings/security")
  1324. return
  1325. }
  1326. handleSignInFull(ctx, u, remember, true)
  1327. }
  1328. // MustChangePassword renders the page to change a user's password
  1329. func MustChangePassword(ctx *context.Context) {
  1330. ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
  1331. ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password"
  1332. ctx.HTML(200, tplMustChangePassword)
  1333. }
  1334. // MustChangePasswordPost response for updating a user's password after his/her
  1335. // account was created by an admin
  1336. func MustChangePasswordPost(ctx *context.Context, cpt *captcha.Captcha, form auth.MustChangePasswordForm) {
  1337. ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
  1338. ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password"
  1339. if ctx.HasError() {
  1340. ctx.HTML(200, tplMustChangePassword)
  1341. return
  1342. }
  1343. u := ctx.User
  1344. // Make sure only requests for users who are eligible to change their password via
  1345. // this method passes through
  1346. if !u.MustChangePassword {
  1347. ctx.ServerError("MustUpdatePassword", errors.New("cannot update password.. Please visit the settings page"))
  1348. return
  1349. }
  1350. if form.Password != form.Retype {
  1351. ctx.Data["Err_Password"] = true
  1352. ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplMustChangePassword, &form)
  1353. return
  1354. }
  1355. if len(form.Password) < setting.MinPasswordLength {
  1356. ctx.Data["Err_Password"] = true
  1357. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplMustChangePassword, &form)
  1358. return
  1359. }
  1360. var err error
  1361. if u.Salt, err = models.GetUserSalt(); err != nil {
  1362. ctx.ServerError("UpdateUser", err)
  1363. return
  1364. }
  1365. u.HashPassword(form.Password)
  1366. u.MustChangePassword = false
  1367. if err := models.UpdateUserCols(u, "must_change_password", "passwd", "salt"); err != nil {
  1368. ctx.ServerError("UpdateUser", err)
  1369. return
  1370. }
  1371. ctx.Flash.Success(ctx.Tr("settings.change_password_success"))
  1372. log.Trace("User updated password: %s", u.Name)
  1373. if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 && !util.IsExternalURL(redirectTo) {
  1374. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL)
  1375. ctx.RedirectToFirst(redirectTo)
  1376. return
  1377. }
  1378. ctx.Redirect(setting.AppSubURL + "/")
  1379. }