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 45 kB

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