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 50 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
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
6 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
8 years ago
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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569
  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. // If this user is enrolled in 2FA, we can't sign the user in just yet.
  190. // Instead, redirect them to the 2FA authentication page.
  191. _, err = models.GetTwoFactorByUID(u.ID)
  192. if err != nil {
  193. if models.IsErrTwoFactorNotEnrolled(err) {
  194. handleSignIn(ctx, u, form.Remember)
  195. } else {
  196. ctx.ServerError("UserSignIn", err)
  197. }
  198. return
  199. }
  200. // User needs to use 2FA, save data and redirect to 2FA page.
  201. if err := ctx.Session.Set("twofaUid", u.ID); err != nil {
  202. ctx.ServerError("UserSignIn: Unable to set twofaUid in session", err)
  203. return
  204. }
  205. if err := ctx.Session.Set("twofaRemember", form.Remember); err != nil {
  206. ctx.ServerError("UserSignIn: Unable to set twofaRemember in session", err)
  207. return
  208. }
  209. if err := ctx.Session.Release(); err != nil {
  210. ctx.ServerError("UserSignIn: Unable to save session", err)
  211. return
  212. }
  213. regs, err := models.GetU2FRegistrationsByUID(u.ID)
  214. if err == nil && len(regs) > 0 {
  215. ctx.Redirect(setting.AppSubURL + "/user/u2f")
  216. return
  217. }
  218. ctx.Redirect(setting.AppSubURL + "/user/two_factor")
  219. }
  220. // TwoFactor shows the user a two-factor authentication page.
  221. func TwoFactor(ctx *context.Context) {
  222. ctx.Data["Title"] = ctx.Tr("twofa")
  223. // Check auto-login.
  224. if checkAutoLogin(ctx) {
  225. return
  226. }
  227. // Ensure user is in a 2FA session.
  228. if ctx.Session.Get("twofaUid") == nil {
  229. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  230. return
  231. }
  232. ctx.HTML(200, tplTwofa)
  233. }
  234. // TwoFactorPost validates a user's two-factor authentication token.
  235. func TwoFactorPost(ctx *context.Context, form auth.TwoFactorAuthForm) {
  236. ctx.Data["Title"] = ctx.Tr("twofa")
  237. // Ensure user is in a 2FA session.
  238. idSess := ctx.Session.Get("twofaUid")
  239. if idSess == nil {
  240. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  241. return
  242. }
  243. id := idSess.(int64)
  244. twofa, err := models.GetTwoFactorByUID(id)
  245. if err != nil {
  246. ctx.ServerError("UserSignIn", err)
  247. return
  248. }
  249. // Validate the passcode with the stored TOTP secret.
  250. ok, err := twofa.ValidateTOTP(form.Passcode)
  251. if err != nil {
  252. ctx.ServerError("UserSignIn", err)
  253. return
  254. }
  255. if ok && twofa.LastUsedPasscode != form.Passcode {
  256. remember := ctx.Session.Get("twofaRemember").(bool)
  257. u, err := models.GetUserByID(id)
  258. if err != nil {
  259. ctx.ServerError("UserSignIn", err)
  260. return
  261. }
  262. if ctx.Session.Get("linkAccount") != nil {
  263. gothUser := ctx.Session.Get("linkAccountGothUser")
  264. if gothUser == nil {
  265. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  266. return
  267. }
  268. err = externalaccount.LinkAccountToUser(u, gothUser.(goth.User))
  269. if err != nil {
  270. ctx.ServerError("UserSignIn", err)
  271. return
  272. }
  273. }
  274. twofa.LastUsedPasscode = form.Passcode
  275. if err = models.UpdateTwoFactor(twofa); err != nil {
  276. ctx.ServerError("UserSignIn", err)
  277. return
  278. }
  279. handleSignIn(ctx, u, remember)
  280. return
  281. }
  282. ctx.RenderWithErr(ctx.Tr("auth.twofa_passcode_incorrect"), tplTwofa, auth.TwoFactorAuthForm{})
  283. }
  284. // TwoFactorScratch shows the scratch code form for two-factor authentication.
  285. func TwoFactorScratch(ctx *context.Context) {
  286. ctx.Data["Title"] = ctx.Tr("twofa_scratch")
  287. // Check auto-login.
  288. if checkAutoLogin(ctx) {
  289. return
  290. }
  291. // Ensure user is in a 2FA session.
  292. if ctx.Session.Get("twofaUid") == nil {
  293. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  294. return
  295. }
  296. ctx.HTML(200, tplTwofaScratch)
  297. }
  298. // TwoFactorScratchPost validates and invalidates a user's two-factor scratch token.
  299. func TwoFactorScratchPost(ctx *context.Context, form auth.TwoFactorScratchAuthForm) {
  300. ctx.Data["Title"] = ctx.Tr("twofa_scratch")
  301. // Ensure user is in a 2FA session.
  302. idSess := ctx.Session.Get("twofaUid")
  303. if idSess == nil {
  304. ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
  305. return
  306. }
  307. id := idSess.(int64)
  308. twofa, err := models.GetTwoFactorByUID(id)
  309. if err != nil {
  310. ctx.ServerError("UserSignIn", err)
  311. return
  312. }
  313. // Validate the passcode with the stored TOTP secret.
  314. if twofa.VerifyScratchToken(form.Token) {
  315. // Invalidate the scratch token.
  316. _, err = twofa.GenerateScratchToken()
  317. if err != nil {
  318. ctx.ServerError("UserSignIn", err)
  319. return
  320. }
  321. if err = models.UpdateTwoFactor(twofa); err != nil {
  322. ctx.ServerError("UserSignIn", err)
  323. return
  324. }
  325. remember := ctx.Session.Get("twofaRemember").(bool)
  326. u, err := models.GetUserByID(id)
  327. if err != nil {
  328. ctx.ServerError("UserSignIn", err)
  329. return
  330. }
  331. handleSignInFull(ctx, u, remember, false)
  332. ctx.Flash.Info(ctx.Tr("auth.twofa_scratch_used"))
  333. ctx.Redirect(setting.AppSubURL + "/user/settings/security")
  334. return
  335. }
  336. ctx.RenderWithErr(ctx.Tr("auth.twofa_scratch_token_incorrect"), tplTwofaScratch, auth.TwoFactorScratchAuthForm{})
  337. }
  338. // U2F shows the U2F login page
  339. func U2F(ctx *context.Context) {
  340. ctx.Data["Title"] = ctx.Tr("twofa")
  341. ctx.Data["RequireU2F"] = true
  342. // Check auto-login.
  343. if checkAutoLogin(ctx) {
  344. return
  345. }
  346. // Ensure user is in a 2FA session.
  347. if ctx.Session.Get("twofaUid") == nil {
  348. ctx.ServerError("UserSignIn", errors.New("not in U2F session"))
  349. return
  350. }
  351. ctx.HTML(200, tplU2F)
  352. }
  353. // U2FChallenge submits a sign challenge to the browser
  354. func U2FChallenge(ctx *context.Context) {
  355. // Ensure user is in a U2F session.
  356. idSess := ctx.Session.Get("twofaUid")
  357. if idSess == nil {
  358. ctx.ServerError("UserSignIn", errors.New("not in U2F session"))
  359. return
  360. }
  361. id := idSess.(int64)
  362. regs, err := models.GetU2FRegistrationsByUID(id)
  363. if err != nil {
  364. ctx.ServerError("UserSignIn", err)
  365. return
  366. }
  367. if len(regs) == 0 {
  368. ctx.ServerError("UserSignIn", errors.New("no device registered"))
  369. return
  370. }
  371. challenge, err := u2f.NewChallenge(setting.U2F.AppID, setting.U2F.TrustedFacets)
  372. if err != nil {
  373. ctx.ServerError("u2f.NewChallenge", err)
  374. return
  375. }
  376. if err := ctx.Session.Set("u2fChallenge", challenge); err != nil {
  377. ctx.ServerError("UserSignIn: unable to set u2fChallenge in session", err)
  378. return
  379. }
  380. if err := ctx.Session.Release(); err != nil {
  381. ctx.ServerError("UserSignIn: unable to store session", err)
  382. }
  383. ctx.JSON(200, challenge.SignRequest(regs.ToRegistrations()))
  384. }
  385. // U2FSign authenticates the user by signResp
  386. func U2FSign(ctx *context.Context, signResp u2f.SignResponse) {
  387. challSess := ctx.Session.Get("u2fChallenge")
  388. idSess := ctx.Session.Get("twofaUid")
  389. if challSess == nil || idSess == nil {
  390. ctx.ServerError("UserSignIn", errors.New("not in U2F session"))
  391. return
  392. }
  393. challenge := challSess.(*u2f.Challenge)
  394. id := idSess.(int64)
  395. regs, err := models.GetU2FRegistrationsByUID(id)
  396. if err != nil {
  397. ctx.ServerError("UserSignIn", err)
  398. return
  399. }
  400. for _, reg := range regs {
  401. r, err := reg.Parse()
  402. if err != nil {
  403. log.Fatal("parsing u2f registration: %v", err)
  404. continue
  405. }
  406. newCounter, authErr := r.Authenticate(signResp, *challenge, reg.Counter)
  407. if authErr == nil {
  408. reg.Counter = newCounter
  409. user, err := models.GetUserByID(id)
  410. if err != nil {
  411. ctx.ServerError("UserSignIn", err)
  412. return
  413. }
  414. remember := ctx.Session.Get("twofaRemember").(bool)
  415. if err := reg.UpdateCounter(); err != nil {
  416. ctx.ServerError("UserSignIn", err)
  417. return
  418. }
  419. if ctx.Session.Get("linkAccount") != nil {
  420. gothUser := ctx.Session.Get("linkAccountGothUser")
  421. if gothUser == nil {
  422. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  423. return
  424. }
  425. err = externalaccount.LinkAccountToUser(user, gothUser.(goth.User))
  426. if err != nil {
  427. ctx.ServerError("UserSignIn", err)
  428. return
  429. }
  430. }
  431. redirect := handleSignInFull(ctx, user, remember, false)
  432. if redirect == "" {
  433. redirect = setting.AppSubURL + "/"
  434. }
  435. ctx.PlainText(200, []byte(redirect))
  436. return
  437. }
  438. }
  439. ctx.Error(401)
  440. }
  441. // This handles the final part of the sign-in process of the user.
  442. func handleSignIn(ctx *context.Context, u *models.User, remember bool) {
  443. handleSignInFull(ctx, u, remember, true)
  444. }
  445. func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyRedirect bool) string {
  446. if remember {
  447. days := 86400 * setting.LogInRememberDays
  448. ctx.SetCookie(setting.CookieUserName, u.Name, days, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  449. ctx.SetSuperSecureCookie(base.EncodeMD5(u.Rands+u.Passwd),
  450. setting.CookieRememberName, u.Name, days, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  451. }
  452. _ = ctx.Session.Delete("openid_verified_uri")
  453. _ = ctx.Session.Delete("openid_signin_remember")
  454. _ = ctx.Session.Delete("openid_determined_email")
  455. _ = ctx.Session.Delete("openid_determined_username")
  456. _ = ctx.Session.Delete("twofaUid")
  457. _ = ctx.Session.Delete("twofaRemember")
  458. _ = ctx.Session.Delete("u2fChallenge")
  459. _ = ctx.Session.Delete("linkAccount")
  460. if err := ctx.Session.Set("uid", u.ID); err != nil {
  461. log.Error("Error setting uid %d in session: %v", u.ID, err)
  462. }
  463. if err := ctx.Session.Set("uname", u.Name); err != nil {
  464. log.Error("Error setting uname %s session: %v", u.Name, err)
  465. }
  466. if err := ctx.Session.Release(); err != nil {
  467. log.Error("Unable to store session: %v", err)
  468. }
  469. // Language setting of the user overwrites the one previously set
  470. // If the user does not have a locale set, we save the current one.
  471. if len(u.Language) == 0 {
  472. u.Language = ctx.Locale.Language()
  473. if err := models.UpdateUserCols(u, "language"); err != nil {
  474. log.Error(fmt.Sprintf("Error updating user language [user: %d, locale: %s]", u.ID, u.Language))
  475. return setting.AppSubURL + "/"
  476. }
  477. }
  478. ctx.SetCookie("lang", u.Language, nil, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  479. // Clear whatever CSRF has right now, force to generate a new one
  480. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  481. // Register last login
  482. u.SetLastLogin()
  483. if err := models.UpdateUserCols(u, "last_login_unix"); err != nil {
  484. ctx.ServerError("UpdateUserCols", err)
  485. return setting.AppSubURL + "/"
  486. }
  487. if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 && !util.IsExternalURL(redirectTo) {
  488. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  489. if obeyRedirect {
  490. ctx.RedirectToFirst(redirectTo)
  491. }
  492. return redirectTo
  493. }
  494. if obeyRedirect {
  495. ctx.Redirect(setting.AppSubURL + "/")
  496. }
  497. return setting.AppSubURL + "/"
  498. }
  499. // SignInOAuth handles the OAuth2 login buttons
  500. func SignInOAuth(ctx *context.Context) {
  501. provider := ctx.Params(":provider")
  502. loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider)
  503. if err != nil {
  504. ctx.ServerError("SignIn", err)
  505. return
  506. }
  507. // try to do a direct callback flow, so we don't authenticate the user again but use the valid accesstoken to get the user
  508. user, gothUser, err := oAuth2UserLoginCallback(loginSource, ctx.Req.Request, ctx.Resp)
  509. if err == nil && user != nil {
  510. // we got the user without going through the whole OAuth2 authentication flow again
  511. handleOAuth2SignIn(user, gothUser, ctx, err)
  512. return
  513. }
  514. err = oauth2.Auth(loginSource.Name, ctx.Req.Request, ctx.Resp)
  515. if err != nil {
  516. ctx.ServerError("SignIn", err)
  517. }
  518. // redirect is done in oauth2.Auth
  519. }
  520. // SignInOAuthCallback handles the callback from the given provider
  521. func SignInOAuthCallback(ctx *context.Context) {
  522. provider := ctx.Params(":provider")
  523. // first look if the provider is still active
  524. loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider)
  525. if err != nil {
  526. ctx.ServerError("SignIn", err)
  527. return
  528. }
  529. if loginSource == nil {
  530. ctx.ServerError("SignIn", errors.New("No valid provider found, check configured callback url in provider"))
  531. return
  532. }
  533. u, gothUser, err := oAuth2UserLoginCallback(loginSource, ctx.Req.Request, ctx.Resp)
  534. handleOAuth2SignIn(u, gothUser, ctx, err)
  535. }
  536. func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context, err error) {
  537. if err != nil {
  538. ctx.ServerError("UserSignIn", err)
  539. return
  540. }
  541. if u == nil {
  542. // no existing user is found, request attach or new account
  543. if err := ctx.Session.Set("linkAccountGothUser", gothUser); err != nil {
  544. log.Error("Error setting linkAccountGothUser in session: %v", err)
  545. }
  546. if err := ctx.Session.Release(); err != nil {
  547. log.Error("Error storing session: %v", err)
  548. }
  549. ctx.Redirect(setting.AppSubURL + "/user/link_account")
  550. return
  551. }
  552. // If this user is enrolled in 2FA, we can't sign the user in just yet.
  553. // Instead, redirect them to the 2FA authentication page.
  554. _, err = models.GetTwoFactorByUID(u.ID)
  555. if err != nil {
  556. if !models.IsErrTwoFactorNotEnrolled(err) {
  557. ctx.ServerError("UserSignIn", err)
  558. return
  559. }
  560. if err := ctx.Session.Set("uid", u.ID); err != nil {
  561. log.Error("Error setting uid in session: %v", err)
  562. }
  563. if err := ctx.Session.Set("uname", u.Name); err != nil {
  564. log.Error("Error setting uname in session: %v", err)
  565. }
  566. if err := ctx.Session.Release(); err != nil {
  567. log.Error("Error storing session: %v", err)
  568. }
  569. // Clear whatever CSRF has right now, force to generate a new one
  570. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  571. // Register last login
  572. u.SetLastLogin()
  573. if err := models.UpdateUserCols(u, "last_login_unix"); err != nil {
  574. ctx.ServerError("UpdateUserCols", err)
  575. return
  576. }
  577. // update external user information
  578. if err := models.UpdateExternalUser(u, gothUser); err != nil {
  579. log.Error("UpdateExternalUser failed: %v", err)
  580. }
  581. if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 {
  582. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL, "", setting.SessionConfig.Secure, true)
  583. ctx.RedirectToFirst(redirectTo)
  584. return
  585. }
  586. ctx.Redirect(setting.AppSubURL + "/")
  587. return
  588. }
  589. // User needs to use 2FA, save data and redirect to 2FA page.
  590. if err := ctx.Session.Set("twofaUid", u.ID); err != nil {
  591. log.Error("Error setting twofaUid in session: %v", err)
  592. }
  593. if err := ctx.Session.Set("twofaRemember", false); err != nil {
  594. log.Error("Error setting twofaRemember in session: %v", err)
  595. }
  596. if err := ctx.Session.Release(); err != nil {
  597. log.Error("Error storing session: %v", err)
  598. }
  599. // If U2F is enrolled -> Redirect to U2F instead
  600. regs, err := models.GetU2FRegistrationsByUID(u.ID)
  601. if err == nil && len(regs) > 0 {
  602. ctx.Redirect(setting.AppSubURL + "/user/u2f")
  603. return
  604. }
  605. ctx.Redirect(setting.AppSubURL + "/user/two_factor")
  606. }
  607. // OAuth2UserLoginCallback attempts to handle the callback from the OAuth2 provider and if successful
  608. // login the user
  609. func oAuth2UserLoginCallback(loginSource *models.LoginSource, request *http.Request, response http.ResponseWriter) (*models.User, goth.User, error) {
  610. gothUser, err := oauth2.ProviderCallback(loginSource.Name, request, response)
  611. if err != nil {
  612. if err.Error() == "securecookie: the value is too long" {
  613. 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)
  614. 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)
  615. }
  616. return nil, goth.User{}, err
  617. }
  618. user := &models.User{
  619. LoginName: gothUser.UserID,
  620. LoginType: models.LoginOAuth2,
  621. LoginSource: loginSource.ID,
  622. }
  623. hasUser, err := models.GetUser(user)
  624. if err != nil {
  625. return nil, goth.User{}, err
  626. }
  627. if hasUser {
  628. return user, gothUser, nil
  629. }
  630. // search in external linked users
  631. externalLoginUser := &models.ExternalLoginUser{
  632. ExternalID: gothUser.UserID,
  633. LoginSourceID: loginSource.ID,
  634. }
  635. hasUser, err = models.GetExternalLogin(externalLoginUser)
  636. if err != nil {
  637. return nil, goth.User{}, err
  638. }
  639. if hasUser {
  640. user, err = models.GetUserByID(externalLoginUser.UserID)
  641. return user, gothUser, err
  642. }
  643. // no user found to login
  644. return nil, gothUser, nil
  645. }
  646. // LinkAccount shows the page where the user can decide to login or create a new account
  647. func LinkAccount(ctx *context.Context) {
  648. ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration
  649. ctx.Data["Title"] = ctx.Tr("link_account")
  650. ctx.Data["LinkAccountMode"] = true
  651. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha
  652. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  653. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  654. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  655. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
  656. ctx.Data["ShowRegistrationButton"] = false
  657. // use this to set the right link into the signIn and signUp templates in the link_account template
  658. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
  659. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"
  660. gothUser := ctx.Session.Get("linkAccountGothUser")
  661. if gothUser == nil {
  662. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  663. return
  664. }
  665. uname := gothUser.(goth.User).NickName
  666. email := gothUser.(goth.User).Email
  667. ctx.Data["user_name"] = uname
  668. ctx.Data["email"] = email
  669. if len(email) != 0 {
  670. u, err := models.GetUserByEmail(email)
  671. if err != nil && !models.IsErrUserNotExist(err) {
  672. ctx.ServerError("UserSignIn", err)
  673. return
  674. }
  675. if u != nil {
  676. ctx.Data["user_exists"] = true
  677. }
  678. } else if len(uname) != 0 {
  679. u, err := models.GetUserByName(uname)
  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. }
  688. ctx.HTML(200, tplLinkAccount)
  689. }
  690. // LinkAccountPostSignIn handle the coupling of external account with another account using signIn
  691. func LinkAccountPostSignIn(ctx *context.Context, signInForm auth.SignInForm) {
  692. ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration
  693. ctx.Data["Title"] = ctx.Tr("link_account")
  694. ctx.Data["LinkAccountMode"] = true
  695. ctx.Data["LinkAccountModeSignIn"] = true
  696. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha
  697. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  698. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  699. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  700. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
  701. ctx.Data["ShowRegistrationButton"] = false
  702. // use this to set the right link into the signIn and signUp templates in the link_account template
  703. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
  704. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"
  705. gothUser := ctx.Session.Get("linkAccountGothUser")
  706. if gothUser == nil {
  707. ctx.ServerError("UserSignIn", errors.New("not in LinkAccount session"))
  708. return
  709. }
  710. if ctx.HasError() {
  711. ctx.HTML(200, tplLinkAccount)
  712. return
  713. }
  714. u, err := models.UserSignIn(signInForm.UserName, signInForm.Password)
  715. if err != nil {
  716. if models.IsErrUserNotExist(err) {
  717. ctx.Data["user_exists"] = true
  718. ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplLinkAccount, &signInForm)
  719. } else {
  720. ctx.ServerError("UserLinkAccount", err)
  721. }
  722. return
  723. }
  724. // If this user is enrolled in 2FA, we can't sign the user in just yet.
  725. // Instead, redirect them to the 2FA authentication page.
  726. _, err = models.GetTwoFactorByUID(u.ID)
  727. if err != nil {
  728. if !models.IsErrTwoFactorNotEnrolled(err) {
  729. ctx.ServerError("UserLinkAccount", err)
  730. return
  731. }
  732. err = externalaccount.LinkAccountToUser(u, gothUser.(goth.User))
  733. if err != nil {
  734. ctx.ServerError("UserLinkAccount", err)
  735. return
  736. }
  737. handleSignIn(ctx, u, signInForm.Remember)
  738. return
  739. }
  740. // User needs to use 2FA, save data and redirect to 2FA page.
  741. if err := ctx.Session.Set("twofaUid", u.ID); err != nil {
  742. log.Error("Error setting twofaUid in session: %v", err)
  743. }
  744. if err := ctx.Session.Set("twofaRemember", signInForm.Remember); err != nil {
  745. log.Error("Error setting twofaRemember in session: %v", err)
  746. }
  747. if err := ctx.Session.Set("linkAccount", true); err != nil {
  748. log.Error("Error setting linkAccount in session: %v", err)
  749. }
  750. if err := ctx.Session.Release(); err != nil {
  751. log.Error("Error storing session: %v", err)
  752. }
  753. // If U2F is enrolled -> Redirect to U2F instead
  754. regs, err := models.GetU2FRegistrationsByUID(u.ID)
  755. if err == nil && len(regs) > 0 {
  756. ctx.Redirect(setting.AppSubURL + "/user/u2f")
  757. return
  758. }
  759. ctx.Redirect(setting.AppSubURL + "/user/two_factor")
  760. }
  761. // LinkAccountPostRegister handle the creation of a new account for an external account using signUp
  762. func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterForm) {
  763. // TODO Make insecure passwords optional for local accounts also,
  764. // once email-based Second-Factor Auth is available
  765. ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration
  766. ctx.Data["Title"] = ctx.Tr("link_account")
  767. ctx.Data["LinkAccountMode"] = true
  768. ctx.Data["LinkAccountModeRegister"] = true
  769. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha
  770. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  771. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  772. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  773. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
  774. ctx.Data["ShowRegistrationButton"] = false
  775. // use this to set the right link into the signIn and signUp templates in the link_account template
  776. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
  777. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"
  778. gothUser := ctx.Session.Get("linkAccountGothUser")
  779. if gothUser == nil {
  780. ctx.ServerError("UserSignUp", errors.New("not in LinkAccount session"))
  781. return
  782. }
  783. if ctx.HasError() {
  784. ctx.HTML(200, tplLinkAccount)
  785. return
  786. }
  787. if setting.Service.DisableRegistration {
  788. ctx.Error(403)
  789. return
  790. }
  791. if setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha {
  792. var valid bool
  793. switch setting.Service.CaptchaType {
  794. case setting.ImageCaptcha:
  795. valid = cpt.VerifyReq(ctx.Req)
  796. case setting.ReCaptcha:
  797. valid, _ = recaptcha.Verify(form.GRecaptchaResponse)
  798. default:
  799. ctx.ServerError("Unknown Captcha Type", fmt.Errorf("Unknown Captcha Type: %s", setting.Service.CaptchaType))
  800. return
  801. }
  802. if !valid {
  803. ctx.Data["Err_Captcha"] = true
  804. ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplLinkAccount, &form)
  805. return
  806. }
  807. }
  808. if setting.Service.AllowOnlyExternalRegistration || !setting.Service.RequireExternalRegistrationPassword {
  809. // In models.User an empty password is classed as not set, so we set form.Password to empty.
  810. // Eventually the database should be changed to indicate "Second Factor"-enabled accounts
  811. // (accounts that do not introduce the security vulnerabilities of a password).
  812. // If a user decides to circumvent second-factor security, and purposefully create a password,
  813. // they can still do so using the "Recover Account" option.
  814. form.Password = ""
  815. } else {
  816. if (len(strings.TrimSpace(form.Password)) > 0 || len(strings.TrimSpace(form.Retype)) > 0) && form.Password != form.Retype {
  817. ctx.Data["Err_Password"] = true
  818. ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplLinkAccount, &form)
  819. return
  820. }
  821. if len(strings.TrimSpace(form.Password)) > 0 && len(form.Password) < setting.MinPasswordLength {
  822. ctx.Data["Err_Password"] = true
  823. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplLinkAccount, &form)
  824. return
  825. }
  826. }
  827. loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.(goth.User).Provider)
  828. if err != nil {
  829. ctx.ServerError("CreateUser", err)
  830. }
  831. u := &models.User{
  832. Name: form.UserName,
  833. Email: form.Email,
  834. Passwd: form.Password,
  835. IsActive: !setting.Service.RegisterEmailConfirm,
  836. LoginType: models.LoginOAuth2,
  837. LoginSource: loginSource.ID,
  838. LoginName: gothUser.(goth.User).UserID,
  839. }
  840. //nolint: dupl
  841. if err := models.CreateUser(u); err != nil {
  842. switch {
  843. case models.IsErrUserAlreadyExist(err):
  844. ctx.Data["Err_UserName"] = true
  845. ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplLinkAccount, &form)
  846. case models.IsErrEmailAlreadyUsed(err):
  847. ctx.Data["Err_Email"] = true
  848. ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplLinkAccount, &form)
  849. case models.IsErrNameReserved(err):
  850. ctx.Data["Err_UserName"] = true
  851. ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tplLinkAccount, &form)
  852. case models.IsErrNamePatternNotAllowed(err):
  853. ctx.Data["Err_UserName"] = true
  854. ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplLinkAccount, &form)
  855. case models.IsErrNameCharsNotAllowed(err):
  856. ctx.Data["Err_UserName"] = true
  857. ctx.RenderWithErr(ctx.Tr("user.form.name_chars_not_allowed", err.(models.ErrNameCharsNotAllowed).Name), tplLinkAccount, &form)
  858. default:
  859. ctx.ServerError("CreateUser", err)
  860. }
  861. return
  862. }
  863. log.Trace("Account created: %s", u.Name)
  864. // Auto-set admin for the only user.
  865. if models.CountUsers() == 1 {
  866. u.IsAdmin = true
  867. u.IsActive = true
  868. u.SetLastLogin()
  869. if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil {
  870. ctx.ServerError("UpdateUser", err)
  871. return
  872. }
  873. }
  874. // update external user information
  875. if err := models.UpdateExternalUser(u, gothUser.(goth.User)); err != nil {
  876. log.Error("UpdateExternalUser failed: %v", err)
  877. }
  878. // Send confirmation email
  879. if setting.Service.RegisterEmailConfirm && u.ID > 1 {
  880. mailer.SendActivateAccountMail(ctx.Locale, u)
  881. ctx.Data["IsSendRegisterMail"] = true
  882. ctx.Data["Email"] = u.Email
  883. ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
  884. ctx.HTML(200, TplActivate)
  885. if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
  886. log.Error("Set cache(MailResendLimit) fail: %v", err)
  887. }
  888. return
  889. }
  890. ctx.Redirect(setting.AppSubURL + "/user/login")
  891. }
  892. // HandleSignOut resets the session and sets the cookies
  893. func HandleSignOut(ctx *context.Context) {
  894. _ = ctx.Session.Flush()
  895. _ = ctx.Session.Destroy(ctx.Context)
  896. ctx.SetCookie(setting.CookieUserName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  897. ctx.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  898. ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL, setting.SessionConfig.Domain, setting.SessionConfig.Secure, true)
  899. 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.
  900. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL) // logout default should set redirect to to default
  901. }
  902. // SignOut sign out from login status
  903. func SignOut(ctx *context.Context) {
  904. if ctx.User != nil {
  905. eventsource.GetManager().SendMessageBlocking(ctx.User.ID, &eventsource.Event{
  906. Name: "logout",
  907. Data: ctx.Session.ID(),
  908. })
  909. }
  910. HandleSignOut(ctx)
  911. ctx.Redirect(setting.AppSubURL + "/")
  912. }
  913. // SignUp render the register page
  914. func SignUp(ctx *context.Context) {
  915. ctx.Data["Title"] = ctx.Tr("sign_up")
  916. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
  917. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
  918. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  919. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  920. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  921. ctx.Data["PageIsSignUp"] = true
  922. //Show Disabled Registration message if DisableRegistration or AllowOnlyExternalRegistration options are true
  923. ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration || setting.Service.AllowOnlyExternalRegistration
  924. ctx.HTML(200, tplSignUp)
  925. }
  926. // SignUpPost response for sign up information submission
  927. func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterForm) {
  928. ctx.Data["Title"] = ctx.Tr("sign_up")
  929. ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
  930. ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
  931. ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
  932. ctx.Data["CaptchaType"] = setting.Service.CaptchaType
  933. ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
  934. ctx.Data["PageIsSignUp"] = true
  935. //Permission denied if DisableRegistration or AllowOnlyExternalRegistration options are true
  936. if setting.Service.DisableRegistration || setting.Service.AllowOnlyExternalRegistration {
  937. ctx.Error(403)
  938. return
  939. }
  940. if ctx.HasError() {
  941. ctx.HTML(200, tplSignUp)
  942. return
  943. }
  944. if setting.Service.EnableCaptcha {
  945. var valid bool
  946. switch setting.Service.CaptchaType {
  947. case setting.ImageCaptcha:
  948. valid = cpt.VerifyReq(ctx.Req)
  949. case setting.ReCaptcha:
  950. valid, _ = recaptcha.Verify(form.GRecaptchaResponse)
  951. default:
  952. ctx.ServerError("Unknown Captcha Type", fmt.Errorf("Unknown Captcha Type: %s", setting.Service.CaptchaType))
  953. return
  954. }
  955. if !valid {
  956. ctx.Data["Err_Captcha"] = true
  957. ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplSignUp, &form)
  958. return
  959. }
  960. }
  961. if !form.IsEmailDomainWhitelisted() {
  962. ctx.RenderWithErr(ctx.Tr("auth.email_domain_blacklisted"), tplSignUp, &form)
  963. return
  964. }
  965. if form.Password != form.Retype {
  966. ctx.Data["Err_Password"] = true
  967. ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplSignUp, &form)
  968. return
  969. }
  970. if len(form.Password) < setting.MinPasswordLength {
  971. ctx.Data["Err_Password"] = true
  972. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplSignUp, &form)
  973. return
  974. }
  975. if !password.IsComplexEnough(form.Password) {
  976. ctx.Data["Err_Password"] = true
  977. ctx.RenderWithErr(password.BuildComplexityError(ctx), tplSignUp, &form)
  978. return
  979. }
  980. u := &models.User{
  981. Name: form.UserName,
  982. Email: form.Email,
  983. Passwd: form.Password,
  984. IsActive: !setting.Service.RegisterEmailConfirm,
  985. }
  986. if err := models.CreateUser(u); err != nil {
  987. switch {
  988. case models.IsErrUserAlreadyExist(err):
  989. ctx.Data["Err_UserName"] = true
  990. ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplSignUp, &form)
  991. case models.IsErrEmailAlreadyUsed(err):
  992. ctx.Data["Err_Email"] = true
  993. ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignUp, &form)
  994. case models.IsErrNameReserved(err):
  995. ctx.Data["Err_UserName"] = true
  996. ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tplSignUp, &form)
  997. case models.IsErrNamePatternNotAllowed(err):
  998. ctx.Data["Err_UserName"] = true
  999. ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSignUp, &form)
  1000. default:
  1001. ctx.ServerError("CreateUser", err)
  1002. }
  1003. return
  1004. }
  1005. log.Trace("Account created: %s", u.Name)
  1006. // Auto-set admin for the only user.
  1007. if models.CountUsers() == 1 {
  1008. u.IsAdmin = true
  1009. u.IsActive = true
  1010. u.SetLastLogin()
  1011. if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil {
  1012. ctx.ServerError("UpdateUser", err)
  1013. return
  1014. }
  1015. }
  1016. // Send confirmation email, no need for social account.
  1017. if setting.Service.RegisterEmailConfirm && u.ID > 1 {
  1018. mailer.SendActivateAccountMail(ctx.Locale, u)
  1019. ctx.Data["IsSendRegisterMail"] = true
  1020. ctx.Data["Email"] = u.Email
  1021. ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
  1022. ctx.HTML(200, TplActivate)
  1023. if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
  1024. log.Error("Set cache(MailResendLimit) fail: %v", err)
  1025. }
  1026. return
  1027. }
  1028. ctx.Flash.Success(ctx.Tr("auth.sign_up_successful"))
  1029. handleSignInFull(ctx, u, false, true)
  1030. }
  1031. // Activate render activate user page
  1032. func Activate(ctx *context.Context) {
  1033. code := ctx.Query("code")
  1034. if len(code) == 0 {
  1035. ctx.Data["IsActivatePage"] = true
  1036. if ctx.User.IsActive {
  1037. ctx.Error(404)
  1038. return
  1039. }
  1040. // Resend confirmation email.
  1041. if setting.Service.RegisterEmailConfirm {
  1042. if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) {
  1043. ctx.Data["ResendLimited"] = true
  1044. } else {
  1045. ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
  1046. mailer.SendActivateAccountMail(ctx.Locale, ctx.User)
  1047. if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
  1048. log.Error("Set cache(MailResendLimit) fail: %v", err)
  1049. }
  1050. }
  1051. } else {
  1052. ctx.Data["ServiceNotEnabled"] = true
  1053. }
  1054. ctx.HTML(200, TplActivate)
  1055. return
  1056. }
  1057. // Verify code.
  1058. if user := models.VerifyUserActiveCode(code); user != nil {
  1059. user.IsActive = true
  1060. var err error
  1061. if user.Rands, err = models.GetUserSalt(); err != nil {
  1062. ctx.ServerError("UpdateUser", err)
  1063. return
  1064. }
  1065. if err := models.UpdateUserCols(user, "is_active", "rands"); err != nil {
  1066. if models.IsErrUserNotExist(err) {
  1067. ctx.Error(404)
  1068. } else {
  1069. ctx.ServerError("UpdateUser", err)
  1070. }
  1071. return
  1072. }
  1073. log.Trace("User activated: %s", user.Name)
  1074. if err := ctx.Session.Set("uid", user.ID); err != nil {
  1075. log.Error(fmt.Sprintf("Error setting uid in session: %v", err))
  1076. }
  1077. if err := ctx.Session.Set("uname", user.Name); err != nil {
  1078. log.Error(fmt.Sprintf("Error setting uname in session: %v", err))
  1079. }
  1080. if err := ctx.Session.Release(); err != nil {
  1081. log.Error("Error storing session: %v", err)
  1082. }
  1083. ctx.Flash.Success(ctx.Tr("auth.account_activated"))
  1084. ctx.Redirect(setting.AppSubURL + "/")
  1085. return
  1086. }
  1087. ctx.Data["IsActivateFailed"] = true
  1088. ctx.HTML(200, TplActivate)
  1089. }
  1090. // ActivateEmail render the activate email page
  1091. func ActivateEmail(ctx *context.Context) {
  1092. code := ctx.Query("code")
  1093. emailStr := ctx.Query("email")
  1094. // Verify code.
  1095. if email := models.VerifyActiveEmailCode(code, emailStr); email != nil {
  1096. if err := email.Activate(); err != nil {
  1097. ctx.ServerError("ActivateEmail", err)
  1098. }
  1099. log.Trace("Email activated: %s", email.Email)
  1100. ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
  1101. if u, err := models.GetUserByID(email.UID); err != nil {
  1102. log.Warn("GetUserByID: %d", email.UID)
  1103. } else {
  1104. // Allow user to validate more emails
  1105. _ = ctx.Cache.Delete("MailResendLimit_" + u.LowerName)
  1106. }
  1107. }
  1108. // FIXME: e-mail verification does not require the user to be logged in,
  1109. // so this could be redirecting to the login page.
  1110. // Should users be logged in automatically here? (consider 2FA requirements, etc.)
  1111. ctx.Redirect(setting.AppSubURL + "/user/settings/account")
  1112. }
  1113. // ForgotPasswd render the forget pasword page
  1114. func ForgotPasswd(ctx *context.Context) {
  1115. ctx.Data["Title"] = ctx.Tr("auth.forgot_password_title")
  1116. if setting.MailService == nil {
  1117. ctx.Data["IsResetDisable"] = true
  1118. ctx.HTML(200, tplForgotPassword)
  1119. return
  1120. }
  1121. email := ctx.Query("email")
  1122. ctx.Data["Email"] = email
  1123. ctx.Data["IsResetRequest"] = true
  1124. ctx.HTML(200, tplForgotPassword)
  1125. }
  1126. // ForgotPasswdPost response for forget password request
  1127. func ForgotPasswdPost(ctx *context.Context) {
  1128. ctx.Data["Title"] = ctx.Tr("auth.forgot_password_title")
  1129. if setting.MailService == nil {
  1130. ctx.NotFound("ForgotPasswdPost", nil)
  1131. return
  1132. }
  1133. ctx.Data["IsResetRequest"] = true
  1134. email := ctx.Query("email")
  1135. ctx.Data["Email"] = email
  1136. u, err := models.GetUserByEmail(email)
  1137. if err != nil {
  1138. if models.IsErrUserNotExist(err) {
  1139. ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
  1140. ctx.Data["IsResetSent"] = true
  1141. ctx.HTML(200, tplForgotPassword)
  1142. return
  1143. }
  1144. ctx.ServerError("user.ResetPasswd(check existence)", err)
  1145. return
  1146. }
  1147. if !u.IsLocal() && !u.IsOAuth2() {
  1148. ctx.Data["Err_Email"] = true
  1149. ctx.RenderWithErr(ctx.Tr("auth.non_local_account"), tplForgotPassword, nil)
  1150. return
  1151. }
  1152. if ctx.Cache.IsExist("MailResendLimit_" + u.LowerName) {
  1153. ctx.Data["ResendLimited"] = true
  1154. ctx.HTML(200, tplForgotPassword)
  1155. return
  1156. }
  1157. mailer.SendResetPasswordMail(ctx.Locale, u)
  1158. if err = ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
  1159. log.Error("Set cache(MailResendLimit) fail: %v", err)
  1160. }
  1161. ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
  1162. ctx.Data["IsResetSent"] = true
  1163. ctx.HTML(200, tplForgotPassword)
  1164. }
  1165. func commonResetPassword(ctx *context.Context) (*models.User, *models.TwoFactor) {
  1166. code := ctx.Query("code")
  1167. ctx.Data["Title"] = ctx.Tr("auth.reset_password")
  1168. ctx.Data["Code"] = code
  1169. if nil != ctx.User {
  1170. ctx.Data["user_signed_in"] = true
  1171. }
  1172. if len(code) == 0 {
  1173. ctx.Flash.Error(ctx.Tr("auth.invalid_code"))
  1174. return nil, nil
  1175. }
  1176. // Fail early, don't frustrate the user
  1177. u := models.VerifyUserActiveCode(code)
  1178. if u == nil {
  1179. ctx.Flash.Error(ctx.Tr("auth.invalid_code"))
  1180. return nil, nil
  1181. }
  1182. twofa, err := models.GetTwoFactorByUID(u.ID)
  1183. if err != nil {
  1184. if !models.IsErrTwoFactorNotEnrolled(err) {
  1185. ctx.Error(http.StatusInternalServerError, "CommonResetPassword", err.Error())
  1186. return nil, nil
  1187. }
  1188. } else {
  1189. ctx.Data["has_two_factor"] = true
  1190. ctx.Data["scratch_code"] = ctx.QueryBool("scratch_code")
  1191. }
  1192. // Show the user that they are affecting the account that they intended to
  1193. ctx.Data["user_email"] = u.Email
  1194. if nil != ctx.User && u.ID != ctx.User.ID {
  1195. ctx.Flash.Error(ctx.Tr("auth.reset_password_wrong_user", ctx.User.Email, u.Email))
  1196. return nil, nil
  1197. }
  1198. return u, twofa
  1199. }
  1200. // ResetPasswd render the account recovery page
  1201. func ResetPasswd(ctx *context.Context) {
  1202. ctx.Data["IsResetForm"] = true
  1203. commonResetPassword(ctx)
  1204. if ctx.Written() {
  1205. return
  1206. }
  1207. ctx.HTML(200, tplResetPassword)
  1208. }
  1209. // ResetPasswdPost response from account recovery request
  1210. func ResetPasswdPost(ctx *context.Context) {
  1211. u, twofa := commonResetPassword(ctx)
  1212. if ctx.Written() {
  1213. return
  1214. }
  1215. if u == nil {
  1216. // Flash error has been set
  1217. ctx.HTML(200, tplResetPassword)
  1218. return
  1219. }
  1220. // Validate password length.
  1221. passwd := ctx.Query("password")
  1222. if len(passwd) < setting.MinPasswordLength {
  1223. ctx.Data["IsResetForm"] = true
  1224. ctx.Data["Err_Password"] = true
  1225. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplResetPassword, nil)
  1226. return
  1227. } else if !password.IsComplexEnough(passwd) {
  1228. ctx.Data["IsResetForm"] = true
  1229. ctx.Data["Err_Password"] = true
  1230. ctx.RenderWithErr(password.BuildComplexityError(ctx), tplResetPassword, nil)
  1231. return
  1232. }
  1233. // Handle two-factor
  1234. regenerateScratchToken := false
  1235. if twofa != nil {
  1236. if ctx.QueryBool("scratch_code") {
  1237. if !twofa.VerifyScratchToken(ctx.Query("token")) {
  1238. ctx.Data["IsResetForm"] = true
  1239. ctx.Data["Err_Token"] = true
  1240. ctx.RenderWithErr(ctx.Tr("auth.twofa_scratch_token_incorrect"), tplResetPassword, nil)
  1241. return
  1242. }
  1243. regenerateScratchToken = true
  1244. } else {
  1245. passcode := ctx.Query("passcode")
  1246. ok, err := twofa.ValidateTOTP(passcode)
  1247. if err != nil {
  1248. ctx.Error(http.StatusInternalServerError, "ValidateTOTP", err.Error())
  1249. return
  1250. }
  1251. if !ok || twofa.LastUsedPasscode == passcode {
  1252. ctx.Data["IsResetForm"] = true
  1253. ctx.Data["Err_Passcode"] = true
  1254. ctx.RenderWithErr(ctx.Tr("auth.twofa_passcode_incorrect"), tplResetPassword, nil)
  1255. return
  1256. }
  1257. twofa.LastUsedPasscode = passcode
  1258. if err = models.UpdateTwoFactor(twofa); err != nil {
  1259. ctx.ServerError("ResetPasswdPost: UpdateTwoFactor", err)
  1260. return
  1261. }
  1262. }
  1263. }
  1264. var err error
  1265. if u.Rands, err = models.GetUserSalt(); err != nil {
  1266. ctx.ServerError("UpdateUser", err)
  1267. return
  1268. }
  1269. if u.Salt, err = models.GetUserSalt(); err != nil {
  1270. ctx.ServerError("UpdateUser", err)
  1271. return
  1272. }
  1273. u.HashPassword(passwd)
  1274. u.MustChangePassword = false
  1275. if err := models.UpdateUserCols(u, "must_change_password", "passwd", "rands", "salt"); err != nil {
  1276. ctx.ServerError("UpdateUser", err)
  1277. return
  1278. }
  1279. log.Trace("User password reset: %s", u.Name)
  1280. ctx.Data["IsResetFailed"] = true
  1281. remember := len(ctx.Query("remember")) != 0
  1282. if regenerateScratchToken {
  1283. // Invalidate the scratch token.
  1284. _, err = twofa.GenerateScratchToken()
  1285. if err != nil {
  1286. ctx.ServerError("UserSignIn", err)
  1287. return
  1288. }
  1289. if err = models.UpdateTwoFactor(twofa); err != nil {
  1290. ctx.ServerError("UserSignIn", err)
  1291. return
  1292. }
  1293. handleSignInFull(ctx, u, remember, false)
  1294. ctx.Flash.Info(ctx.Tr("auth.twofa_scratch_used"))
  1295. ctx.Redirect(setting.AppSubURL + "/user/settings/security")
  1296. return
  1297. }
  1298. handleSignInFull(ctx, u, remember, true)
  1299. }
  1300. // MustChangePassword renders the page to change a user's password
  1301. func MustChangePassword(ctx *context.Context) {
  1302. ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
  1303. ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password"
  1304. ctx.HTML(200, tplMustChangePassword)
  1305. }
  1306. // MustChangePasswordPost response for updating a user's password after his/her
  1307. // account was created by an admin
  1308. func MustChangePasswordPost(ctx *context.Context, cpt *captcha.Captcha, form auth.MustChangePasswordForm) {
  1309. ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
  1310. ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password"
  1311. if ctx.HasError() {
  1312. ctx.HTML(200, tplMustChangePassword)
  1313. return
  1314. }
  1315. u := ctx.User
  1316. // Make sure only requests for users who are eligible to change their password via
  1317. // this method passes through
  1318. if !u.MustChangePassword {
  1319. ctx.ServerError("MustUpdatePassword", errors.New("cannot update password.. Please visit the settings page"))
  1320. return
  1321. }
  1322. if form.Password != form.Retype {
  1323. ctx.Data["Err_Password"] = true
  1324. ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplMustChangePassword, &form)
  1325. return
  1326. }
  1327. if len(form.Password) < setting.MinPasswordLength {
  1328. ctx.Data["Err_Password"] = true
  1329. ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplMustChangePassword, &form)
  1330. return
  1331. }
  1332. var err error
  1333. if u.Salt, err = models.GetUserSalt(); err != nil {
  1334. ctx.ServerError("UpdateUser", err)
  1335. return
  1336. }
  1337. u.HashPassword(form.Password)
  1338. u.MustChangePassword = false
  1339. if err := models.UpdateUserCols(u, "must_change_password", "passwd", "salt"); err != nil {
  1340. ctx.ServerError("UpdateUser", err)
  1341. return
  1342. }
  1343. ctx.Flash.Success(ctx.Tr("settings.change_password_success"))
  1344. log.Trace("User updated password: %s", u.Name)
  1345. if redirectTo := ctx.GetCookie("redirect_to"); len(redirectTo) > 0 && !util.IsExternalURL(redirectTo) {
  1346. ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL)
  1347. ctx.RedirectToFirst(redirectTo)
  1348. return
  1349. }
  1350. ctx.Redirect(setting.AppSubURL + "/")
  1351. }