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

auth.go 51 kB

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