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

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
3 years ago
3 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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package user
  6. import (
  7. "errors"
  8. "fmt"
  9. "net/http"
  10. "strings"
  11. "code.gitea.io/gitea/models"
  12. "code.gitea.io/gitea/modules/auth"
  13. "code.gitea.io/gitea/modules/auth/oauth2"
  14. "code.gitea.io/gitea/modules/base"
  15. "code.gitea.io/gitea/modules/context"
  16. "code.gitea.io/gitea/modules/eventsource"
  17. "code.gitea.io/gitea/modules/log"
  18. "code.gitea.io/gitea/modules/password"
  19. "code.gitea.io/gitea/modules/recaptcha"
  20. "code.gitea.io/gitea/modules/setting"
  21. "code.gitea.io/gitea/modules/timeutil"
  22. "code.gitea.io/gitea/modules/util"
  23. "code.gitea.io/gitea/services/externalaccount"
  24. "code.gitea.io/gitea/services/mailer"
  25. "gitea.com/macaron/captcha"
  26. "github.com/markbates/goth"
  27. "github.com/tstranex/u2f"
  28. )
  29. const (
  30. // tplMustChangePassword template for updating a user's password
  31. tplMustChangePassword = "user/auth/change_passwd"
  32. // tplSignIn template for sign in page
  33. tplSignIn base.TplName = "user/auth/signin"
  34. // tplSignIn template for sign in page
  35. tplSignInCloudBrain base.TplName = "user/auth/signin_cloud_brain"
  36. // tplSignUp template path for sign up page
  37. tplSignUp base.TplName = "user/auth/signup"
  38. // TplActivate template path for activate user
  39. TplActivate base.TplName = "user/auth/activate"
  40. tplForgotPassword base.TplName = "user/auth/forgot_passwd"
  41. tplResetPassword base.TplName = "user/auth/reset_passwd"
  42. tplTwofa base.TplName = "user/auth/twofa"
  43. tplTwofaScratch base.TplName = "user/auth/twofa_scratch"
  44. tplLinkAccount base.TplName = "user/auth/link_account"
  45. tplU2F base.TplName = "user/auth/u2f"
  46. )
  47. // AutoSignIn reads cookie and try to auto-login.
  48. func AutoSignIn(ctx *context.Context) (bool, error) {
  49. if !models.HasEngine {
  50. return false, nil
  51. }
  52. uname := ctx.GetCookie(setting.CookieUserName)
  53. if len(uname) == 0 {
  54. return false, nil
  55. }
  56. isSucceed := false
  57. defer func() {
  58. if !isSucceed {
  59. log.Trace("auto-login cookie cleared: %s", uname)
  60. ctx.SetCookie(setting.CookieUserName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  61. ctx.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  62. }
  63. }()
  64. u, err := models.GetUserByName(uname)
  65. if err != nil {
  66. if !models.IsErrUserNotExist(err) {
  67. return false, fmt.Errorf("GetUserByName: %v", err)
  68. }
  69. return false, nil
  70. }
  71. if val, ok := ctx.GetSuperSecureCookie(
  72. base.EncodeMD5(u.Rands+u.Passwd), setting.CookieRememberName); !ok || val != u.Name {
  73. return false, nil
  74. }
  75. isSucceed = true
  76. // Set session IDs
  77. if err := ctx.Session.Set("uid", u.ID); err != nil {
  78. return false, err
  79. }
  80. if err := ctx.Session.Set("uname", u.Name); err != nil {
  81. return false, err
  82. }
  83. if err := ctx.Session.Release(); err != nil {
  84. return false, err
  85. }
  86. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  87. return true, nil
  88. }
  89. func checkAutoLogin(ctx *context.Context) bool {
  90. // Check auto-login.
  91. isSucceed, err := AutoSignIn(ctx)
  92. if err != nil {
  93. ctx.ServerError("AutoSignIn", err)
  94. return true
  95. }
  96. redirectTo := ctx.Query("redirect_to")
  97. if len(redirectTo) > 0 {
  98. ctx.SetCookie("redirect_to", redirectTo, 0, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  99. } else {
  100. redirectTo = ctx.GetCookie("redirect_to")
  101. }
  102. if isSucceed {
  103. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  104. ctx.RedirectToFirst(redirectTo, setting.AppSubURL+string(setting.LandingPageURL))
  105. return true
  106. }
  107. return false
  108. }
  109. // SignIn render sign in page
  110. func SignIn(ctx *context.Context) {
  111. ctx.Data["Title"] = ctx.Tr("sign_in")
  112. // Check auto-login.
  113. if checkAutoLogin(ctx) {
  114. return
  115. }
  116. orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers()
  117. if err != nil {
  118. ctx.ServerError("UserSignIn", err)
  119. return
  120. }
  121. ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names
  122. ctx.Data["OAuth2Providers"] = oauth2Providers
  123. ctx.Data["Title"] = ctx.Tr("sign_in")
  124. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login"
  125. ctx.Data["PageIsSignIn"] = true
  126. ctx.Data["PageIsLogin"] = true
  127. ctx.Data["EnableSSPI"] = models.IsSSPIEnabled()
  128. ctx.Data["EnableCloudBrain"] = true
  129. ctx.HTML(200, tplSignIn)
  130. }
  131. // SignInCloudBrain render sign in page
  132. func SignInCloudBrain(ctx *context.Context) {
  133. ctx.Data["Title"] = ctx.Tr("sign_in")
  134. // Check auto-login.
  135. if checkAutoLogin(ctx) {
  136. return
  137. }
  138. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login"
  139. ctx.Data["PageIsSignIn"] = true
  140. ctx.Data["PageIsCloudBrainLogin"] = true
  141. ctx.Data["EnableCloudBrain"] = true
  142. ctx.HTML(200, tplSignInCloudBrain)
  143. }
  144. // SignInPost response for sign in request
  145. func SignInPost(ctx *context.Context, form auth.SignInForm) {
  146. ctx.Data["Title"] = ctx.Tr("sign_in")
  147. orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers()
  148. if err != nil {
  149. ctx.ServerError("UserSignIn", err)
  150. return
  151. }
  152. ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names
  153. ctx.Data["OAuth2Providers"] = oauth2Providers
  154. ctx.Data["Title"] = ctx.Tr("sign_in")
  155. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login"
  156. ctx.Data["PageIsSignIn"] = true
  157. ctx.Data["PageIsLogin"] = true
  158. ctx.Data["EnableSSPI"] = models.IsSSPIEnabled()
  159. if ctx.HasError() {
  160. ctx.HTML(200, tplSignIn)
  161. return
  162. }
  163. u, err := models.UserSignIn(form.UserName, form.Password)
  164. if err != nil {
  165. if models.IsErrUserNotExist(err) {
  166. ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form)
  167. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  168. } else if models.IsErrEmailAlreadyUsed(err) {
  169. ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignIn, &form)
  170. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  171. } else if models.IsErrUserProhibitLogin(err) {
  172. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  173. ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
  174. ctx.HTML(200, "user/auth/prohibit_login")
  175. } else if models.IsErrUserInactive(err) {
  176. if setting.Service.RegisterEmailConfirm {
  177. ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
  178. ctx.HTML(200, TplActivate)
  179. } else {
  180. log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr())
  181. ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
  182. ctx.HTML(200, "user/auth/prohibit_login")
  183. }
  184. } else {
  185. ctx.ServerError("UserSignIn", err)
  186. }
  187. return
  188. }
  189. models.SaveLoginInfoToDb(ctx.Req.Request, u)
  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 + "/dashboard"
  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 + "/dashboard"
  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 + "/dashboard")
  505. }
  506. return setting.AppSubURL + "/dashboard"
  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. ctx.Redirect(setting.AppSubURL + "/")
  921. }
  922. // SignUp render the register page
  923. func SignUp(ctx *context.Context) {
  924. ctx.Data["Title"] = ctx.Tr("sign_up")
  925. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
  926. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
  927. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  928. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  929. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  930. ctx.Data["PageIsSignUp"] = true
  931. //Show Disabled Registration message if DisableRegistration or AllowOnlyExternalRegistration options are true
  932. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration || setting.Service.AllowOnlyExternalRegistration
  933. ctx.HTML(200, tplSignUp)
  934. }
  935. // SignUpPost response for sign up information submission
  936. func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterForm) {
  937. ctx.Data["Title"] = ctx.Tr("sign_up")
  938. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
  939. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
  940. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  941. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  942. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  943. ctx.Data["PageIsSignUp"] = true
  944. //Permission denied if DisableRegistration or AllowOnlyExternalRegistration options are true
  945. if setting.Service.DisableRegistration || setting.Service.AllowOnlyExternalRegistration {
  946. ctx.Error(403)
  947. return
  948. }
  949. if ctx.HasError() {
  950. ctx.HTML(200, tplSignUp)
  951. return
  952. }
  953. if setting.Service.EnableCaptcha {
  954. var valid bool
  955. switch setting.Service.CaptchaType {
  956. case setting.ImageCaptcha:
  957. valid = cpt.VerifyReq(ctx.Req)
  958. case setting.ReCaptcha:
  959. valid, _ = recaptcha.Verify(form.GRecaptchaResponse)
  960. default:
  961. ctx.ServerError("Unknown Captcha Type", fmt.Errorf("Unknown Captcha Type: %s", setting.Service.CaptchaType))
  962. return
  963. }
  964. if !valid {
  965. ctx.Data["Err_Captcha"] = true
  966. ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplSignUp, &form)
  967. return
  968. }
  969. }
  970. if !form.IsEmailDomainWhitelisted() {
  971. ctx.RenderWithErr(ctx.Tr("auth.email_domain_blacklisted"), tplSignUp, &form)
  972. return
  973. }
  974. if form.Password != form.Retype {
  975. ctx.Data["Err_Password"] = true
  976. ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplSignUp, &form)
  977. return
  978. }
  979. if len(form.Password) < setting.MinPasswordLength {
  980. ctx.Data["Err_Password"] = true
  981. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplSignUp, &form)
  982. return
  983. }
  984. if !password.IsComplexEnough(form.Password) {
  985. ctx.Data["Err_Password"] = true
  986. ctx.RenderWithErr(password.BuildComplexityError(ctx), tplSignUp, &form)
  987. return
  988. }
  989. u := &models.User{
  990. Name: form.UserName,
  991. Email: form.Email,
  992. Passwd: form.Password,
  993. IsActive: !setting.Service.RegisterEmailConfirm,
  994. }
  995. if err := models.CreateUser(u); err != nil {
  996. switch {
  997. case models.IsErrUserAlreadyExist(err):
  998. ctx.Data["Err_UserName"] = true
  999. ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplSignUp, &form)
  1000. case models.IsErrEmailAlreadyUsed(err):
  1001. ctx.Data["Err_Email"] = true
  1002. ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignUp, &form)
  1003. case models.IsErrNameReserved(err):
  1004. ctx.Data["Err_UserName"] = true
  1005. ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tplSignUp, &form)
  1006. case models.IsErrNamePatternNotAllowed(err):
  1007. ctx.Data["Err_UserName"] = true
  1008. ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSignUp, &form)
  1009. default:
  1010. ctx.ServerError("CreateUser", err)
  1011. }
  1012. return
  1013. }
  1014. log.Trace("Account created: %s", u.Name, ctx.Data["MsgID"])
  1015. err := models.AddEmailAddress(&models.EmailAddress{
  1016. UID: u.ID,
  1017. Email: form.Email,
  1018. IsActivated: !setting.Service.RegisterEmailConfirm,
  1019. })
  1020. if err != nil {
  1021. log.Error("AddEmailAddress failed:%v", err.Error(), ctx.Data["MsgID"])
  1022. ctx.ServerError("AddEmailAddress", err)
  1023. return
  1024. }
  1025. // Auto-set admin for the only user.
  1026. if models.CountUsers() == 1 {
  1027. u.IsAdmin = true
  1028. u.IsActive = true
  1029. u.SetLastLogin()
  1030. if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil {
  1031. ctx.ServerError("UpdateUser", err)
  1032. return
  1033. }
  1034. }
  1035. // Send confirmation email, no need for social account.
  1036. if setting.Service.RegisterEmailConfirm && u.ID > 1 {
  1037. mailer.SendActivateAccountMail(ctx.Locale, u)
  1038. ctx.Data["IsSendRegisterMail"] = true
  1039. ctx.Data["Email"] = u.Email
  1040. ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
  1041. ctx.HTML(200, TplActivate)
  1042. if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
  1043. log.Error("Set cache(MailResendLimit) fail: %v", err)
  1044. }
  1045. return
  1046. }
  1047. ctx.Flash.Success(ctx.Tr("auth.sign_up_successful"))
  1048. handleSignInFull(ctx, u, false, true)
  1049. }
  1050. // Activate render activate user page
  1051. func Activate(ctx *context.Context) {
  1052. code := ctx.Query("code")
  1053. if len(code) == 0 {
  1054. ctx.Data["IsActivatePage"] = true
  1055. if ctx.User.IsActive {
  1056. ctx.Error(404)
  1057. return
  1058. }
  1059. // Resend confirmation email.
  1060. if setting.Service.RegisterEmailConfirm {
  1061. if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) {
  1062. ctx.Data["ResendLimited"] = true
  1063. } else {
  1064. ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
  1065. mailer.SendActivateAccountMail(ctx.Locale, ctx.User)
  1066. if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
  1067. log.Error("Set cache(MailResendLimit) fail: %v", err)
  1068. }
  1069. }
  1070. } else {
  1071. ctx.Data["ServiceNotEnabled"] = true
  1072. }
  1073. ctx.HTML(200, TplActivate)
  1074. return
  1075. }
  1076. // Verify code.
  1077. if user := models.VerifyUserActiveCode(code); user != nil {
  1078. user.IsActive = true
  1079. var err error
  1080. if user.Rands, err = models.GetUserSalt(); err != nil {
  1081. ctx.ServerError("UpdateUser", err)
  1082. return
  1083. }
  1084. if err := models.UpdateUserCols(user, "is_active", "rands"); err != nil {
  1085. if models.IsErrUserNotExist(err) {
  1086. ctx.Error(404)
  1087. } else {
  1088. ctx.ServerError("UpdateUser", err)
  1089. }
  1090. return
  1091. }
  1092. log.Trace("User activated: %s", user.Name)
  1093. if err := ctx.Session.Set("uid", user.ID); err != nil {
  1094. log.Error(fmt.Sprintf("Error setting uid in session: %v", err))
  1095. }
  1096. if err := ctx.Session.Set("uname", user.Name); err != nil {
  1097. log.Error(fmt.Sprintf("Error setting uname in session: %v", err))
  1098. }
  1099. if err := ctx.Session.Release(); err != nil {
  1100. log.Error("Error storing session: %v", err)
  1101. }
  1102. email, err := models.GetEmailAddressByIDAndEmail(user.ID, user.Email)
  1103. if err != nil || email == nil {
  1104. log.Error("GetEmailAddressByIDAndEmail failed", ctx.Data["MsgID"])
  1105. } else {
  1106. if err := email.Activate(); err != nil {
  1107. log.Error("Activate failed: %v", err, ctx.Data["MsgID"])
  1108. }
  1109. }
  1110. ctx.Flash.Success(ctx.Tr("auth.account_activated"))
  1111. ctx.Redirect(setting.AppSubURL + "/")
  1112. return
  1113. }
  1114. ctx.Data["IsActivateFailed"] = true
  1115. ctx.HTML(200, TplActivate)
  1116. }
  1117. // ActivateEmail render the activate email page
  1118. func ActivateEmail(ctx *context.Context) {
  1119. code := ctx.Query("code")
  1120. emailStr := ctx.Query("email")
  1121. // Verify code.
  1122. if email := models.VerifyActiveEmailCode(code, emailStr); email != nil {
  1123. if err := email.Activate(); err != nil {
  1124. ctx.ServerError("ActivateEmail", err)
  1125. }
  1126. log.Trace("Email activated: %s", email.Email)
  1127. ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
  1128. if u, err := models.GetUserByID(email.UID); err != nil {
  1129. log.Warn("GetUserByID: %d", email.UID)
  1130. } else {
  1131. // Allow user to validate more emails
  1132. _ = ctx.Cache.Delete("MailResendLimit_" + u.LowerName)
  1133. }
  1134. }
  1135. // FIXME: e-mail verification does not require the user to be logged in,
  1136. // so this could be redirecting to the login page.
  1137. // Should users be logged in automatically here? (consider 2FA requirements, etc.)
  1138. ctx.Redirect(setting.AppSubURL + "/user/settings/account")
  1139. }
  1140. // ForgotPasswd render the forget pasword page
  1141. func ForgotPasswd(ctx *context.Context) {
  1142. ctx.Data["Title"] = ctx.Tr("auth.forgot_password_title")
  1143. if setting.MailService == nil {
  1144. ctx.Data["IsResetDisable"] = true
  1145. ctx.HTML(200, tplForgotPassword)
  1146. return
  1147. }
  1148. email := ctx.Query("email")
  1149. ctx.Data["Email"] = email
  1150. ctx.Data["IsResetRequest"] = true
  1151. ctx.HTML(200, tplForgotPassword)
  1152. }
  1153. // ForgotPasswdPost response for forget password request
  1154. func ForgotPasswdPost(ctx *context.Context) {
  1155. ctx.Data["Title"] = ctx.Tr("auth.forgot_password_title")
  1156. if setting.MailService == nil {
  1157. ctx.NotFound("ForgotPasswdPost", nil)
  1158. return
  1159. }
  1160. ctx.Data["IsResetRequest"] = true
  1161. email := ctx.Query("email")
  1162. ctx.Data["Email"] = email
  1163. u, err := models.GetUserByEmail(email)
  1164. if err != nil {
  1165. if models.IsErrUserNotExist(err) {
  1166. ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
  1167. ctx.Data["IsResetSent"] = true
  1168. ctx.HTML(200, tplForgotPassword)
  1169. return
  1170. }
  1171. ctx.ServerError("user.ResetPasswd(check existence)", err)
  1172. return
  1173. }
  1174. if !u.IsLocal() && !u.IsOAuth2() {
  1175. ctx.Data["Err_Email"] = true
  1176. ctx.RenderWithErr(ctx.Tr("auth.non_local_account"), tplForgotPassword, nil)
  1177. return
  1178. }
  1179. if ctx.Cache.IsExist("MailResendLimit_" + u.LowerName) {
  1180. ctx.Data["ResendLimited"] = true
  1181. ctx.HTML(200, tplForgotPassword)
  1182. return
  1183. }
  1184. mailer.SendResetPasswordMail(ctx.Locale, u)
  1185. if err = ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
  1186. log.Error("Set cache(MailResendLimit) fail: %v", err)
  1187. }
  1188. ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
  1189. ctx.Data["IsResetSent"] = true
  1190. ctx.HTML(200, tplForgotPassword)
  1191. }
  1192. func commonResetPassword(ctx *context.Context) (*models.User, *models.TwoFactor) {
  1193. code := ctx.Query("code")
  1194. ctx.Data["Title"] = ctx.Tr("auth.reset_password")
  1195. ctx.Data["Code"] = code
  1196. if nil != ctx.User {
  1197. ctx.Data["user_signed_in"] = true
  1198. }
  1199. if len(code) == 0 {
  1200. ctx.Flash.Error(ctx.Tr("auth.invalid_code"))
  1201. return nil, nil
  1202. }
  1203. // Fail early, don't frustrate the user
  1204. u := models.VerifyUserActiveCode(code)
  1205. if u == nil {
  1206. ctx.Flash.Error(ctx.Tr("auth.invalid_code"))
  1207. return nil, nil
  1208. }
  1209. twofa, err := models.GetTwoFactorByUID(u.ID)
  1210. if err != nil {
  1211. if !models.IsErrTwoFactorNotEnrolled(err) {
  1212. ctx.Error(http.StatusInternalServerError, "CommonResetPassword", err.Error())
  1213. return nil, nil
  1214. }
  1215. } else {
  1216. ctx.Data["has_two_factor"] = true
  1217. ctx.Data["scratch_code"] = ctx.QueryBool("scratch_code")
  1218. }
  1219. // Show the user that they are affecting the account that they intended to
  1220. ctx.Data["user_email"] = u.Email
  1221. if nil != ctx.User && u.ID != ctx.User.ID {
  1222. ctx.Flash.Error(ctx.Tr("auth.reset_password_wrong_user", ctx.User.Email, u.Email))
  1223. return nil, nil
  1224. }
  1225. return u, twofa
  1226. }
  1227. // ResetPasswd render the account recovery page
  1228. func ResetPasswd(ctx *context.Context) {
  1229. ctx.Data["IsResetForm"] = true
  1230. commonResetPassword(ctx)
  1231. if ctx.Written() {
  1232. return
  1233. }
  1234. ctx.HTML(200, tplResetPassword)
  1235. }
  1236. // ResetPasswdPost response from account recovery request
  1237. func ResetPasswdPost(ctx *context.Context) {
  1238. u, twofa := commonResetPassword(ctx)
  1239. if ctx.Written() {
  1240. return
  1241. }
  1242. if u == nil {
  1243. // Flash error has been set
  1244. ctx.HTML(200, tplResetPassword)
  1245. return
  1246. }
  1247. // Validate password length.
  1248. passwd := ctx.Query("password")
  1249. if len(passwd) < setting.MinPasswordLength {
  1250. ctx.Data["IsResetForm"] = true
  1251. ctx.Data["Err_Password"] = true
  1252. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplResetPassword, nil)
  1253. return
  1254. } else if !password.IsComplexEnough(passwd) {
  1255. ctx.Data["IsResetForm"] = true
  1256. ctx.Data["Err_Password"] = true
  1257. ctx.RenderWithErr(password.BuildComplexityError(ctx), tplResetPassword, nil)
  1258. return
  1259. }
  1260. // Handle two-factor
  1261. regenerateScratchToken := false
  1262. if twofa != nil {
  1263. if ctx.QueryBool("scratch_code") {
  1264. if !twofa.VerifyScratchToken(ctx.Query("token")) {
  1265. ctx.Data["IsResetForm"] = true
  1266. ctx.Data["Err_Token"] = true
  1267. ctx.RenderWithErr(ctx.Tr("auth.twofa_scratch_token_incorrect"), tplResetPassword, nil)
  1268. return
  1269. }
  1270. regenerateScratchToken = true
  1271. } else {
  1272. passcode := ctx.Query("passcode")
  1273. ok, err := twofa.ValidateTOTP(passcode)
  1274. if err != nil {
  1275. ctx.Error(http.StatusInternalServerError, "ValidateTOTP", err.Error())
  1276. return
  1277. }
  1278. if !ok || twofa.LastUsedPasscode == passcode {
  1279. ctx.Data["IsResetForm"] = true
  1280. ctx.Data["Err_Passcode"] = true
  1281. ctx.RenderWithErr(ctx.Tr("auth.twofa_passcode_incorrect"), tplResetPassword, nil)
  1282. return
  1283. }
  1284. twofa.LastUsedPasscode = passcode
  1285. if err = models.UpdateTwoFactor(twofa); err != nil {
  1286. ctx.ServerError("ResetPasswdPost: UpdateTwoFactor", err)
  1287. return
  1288. }
  1289. }
  1290. }
  1291. var err error
  1292. if u.Rands, err = models.GetUserSalt(); err != nil {
  1293. ctx.ServerError("UpdateUser", err)
  1294. return
  1295. }
  1296. if u.Salt, err = models.GetUserSalt(); err != nil {
  1297. ctx.ServerError("UpdateUser", err)
  1298. return
  1299. }
  1300. u.HashPassword(passwd)
  1301. u.MustChangePassword = false
  1302. if err := models.UpdateUserCols(u, "must_change_password", "passwd", "rands", "salt"); err != nil {
  1303. ctx.ServerError("UpdateUser", err)
  1304. return
  1305. }
  1306. log.Trace("User password reset: %s", u.Name)
  1307. ctx.Data["IsResetFailed"] = true
  1308. remember := len(ctx.Query("remember")) != 0
  1309. if regenerateScratchToken {
  1310. // Invalidate the scratch token.
  1311. _, err = twofa.GenerateScratchToken()
  1312. if err != nil {
  1313. ctx.ServerError("UserSignIn", err)
  1314. return
  1315. }
  1316. if err = models.UpdateTwoFactor(twofa); err != nil {
  1317. ctx.ServerError("UserSignIn", err)
  1318. return
  1319. }
  1320. handleSignInFull(ctx, u, remember, false)
  1321. ctx.Flash.Info(ctx.Tr("auth.twofa_scratch_used"))
  1322. ctx.Redirect(setting.AppSubURL + "/user/settings/security")
  1323. return
  1324. }
  1325. handleSignInFull(ctx, u, remember, true)
  1326. }
  1327. // MustChangePassword renders the page to change a user's password
  1328. func MustChangePassword(ctx *context.Context) {
  1329. ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
  1330. ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password"
  1331. ctx.HTML(200, tplMustChangePassword)
  1332. }
  1333. // MustChangePasswordPost response for updating a user's password after his/her
  1334. // account was created by an admin
  1335. func MustChangePasswordPost(ctx *context.Context, cpt *captcha.Captcha, form auth.MustChangePasswordForm) {
  1336. ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
  1337. ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password"
  1338. if ctx.HasError() {
  1339. ctx.HTML(200, tplMustChangePassword)
  1340. return
  1341. }
  1342. u := ctx.User
  1343. // Make sure only requests for users who are eligible to change their password via
  1344. // this method passes through
  1345. if !u.MustChangePassword {
  1346. ctx.ServerError("MustUpdatePassword", errors.New("cannot update password.. Please visit the settings page"))
  1347. return
  1348. }
  1349. if form.Password != form.Retype {
  1350. ctx.Data["Err_Password"] = true
  1351. ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplMustChangePassword, &form)
  1352. return
  1353. }
  1354. if len(form.Password) < setting.MinPasswordLength {
  1355. ctx.Data["Err_Password"] = true
  1356. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplMustChangePassword, &form)
  1357. return
  1358. }
  1359. var err error
  1360. if u.Salt, err = models.GetUserSalt(); err != nil {
  1361. ctx.ServerError("UpdateUser", err)
  1362. return
  1363. }
  1364. u.HashPassword(form.Password)
  1365. u.MustChangePassword = false
  1366. if err := models.UpdateUserCols(u, "must_change_password", "passwd", "salt"); err != nil {
  1367. ctx.ServerError("UpdateUser", err)
  1368. return
  1369. }
  1370. ctx.Flash.Success(ctx.Tr("settings.change_password_success"))
  1371. log.Trace("User updated password: %s", u.Name)
  1372. if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 && !util.IsExternalURL(redirectTo) {
  1373. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL)
  1374. ctx.RedirectToFirst(redirectTo)
  1375. return
  1376. }
  1377. ctx.Redirect(setting.AppSubURL + "/")
  1378. }