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