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