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.

auths.go 8.9 kB

12 years ago
12 years ago
12 years ago
12 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
9 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
9 years ago
12 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
9 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
9 years ago
12 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
9 years ago
12 years ago
12 years ago
12 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
9 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
9 years ago
12 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
9 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
9 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
9 years ago
12 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package admin
  5. import (
  6. "fmt"
  7. "github.com/Unknwon/com"
  8. "github.com/go-xorm/core"
  9. "code.gitea.io/gitea/models"
  10. "code.gitea.io/gitea/modules/auth"
  11. "code.gitea.io/gitea/modules/auth/ldap"
  12. "code.gitea.io/gitea/modules/base"
  13. "code.gitea.io/gitea/modules/context"
  14. "code.gitea.io/gitea/modules/log"
  15. "code.gitea.io/gitea/modules/setting"
  16. )
  17. const (
  18. tplAuths base.TplName = "admin/auth/list"
  19. tplAuthNew base.TplName = "admin/auth/new"
  20. tplAuthEdit base.TplName = "admin/auth/edit"
  21. )
  22. // Authentications show authentication config page
  23. func Authentications(ctx *context.Context) {
  24. ctx.Data["Title"] = ctx.Tr("admin.authentication")
  25. ctx.Data["PageIsAdmin"] = true
  26. ctx.Data["PageIsAdminAuthentications"] = true
  27. var err error
  28. ctx.Data["Sources"], err = models.LoginSources()
  29. if err != nil {
  30. ctx.Handle(500, "LoginSources", err)
  31. return
  32. }
  33. ctx.Data["Total"] = models.CountLoginSources()
  34. ctx.HTML(200, tplAuths)
  35. }
  36. type dropdownItem struct {
  37. Name string
  38. Type interface{}
  39. }
  40. var (
  41. authSources = []dropdownItem{
  42. {models.LoginNames[models.LoginLDAP], models.LoginLDAP},
  43. {models.LoginNames[models.LoginDLDAP], models.LoginDLDAP},
  44. {models.LoginNames[models.LoginSMTP], models.LoginSMTP},
  45. {models.LoginNames[models.LoginPAM], models.LoginPAM},
  46. {models.LoginNames[models.LoginOAuth2], models.LoginOAuth2},
  47. }
  48. securityProtocols = []dropdownItem{
  49. {models.SecurityProtocolNames[ldap.SecurityProtocolUnencrypted], ldap.SecurityProtocolUnencrypted},
  50. {models.SecurityProtocolNames[ldap.SecurityProtocolLDAPS], ldap.SecurityProtocolLDAPS},
  51. {models.SecurityProtocolNames[ldap.SecurityProtocolStartTLS], ldap.SecurityProtocolStartTLS},
  52. }
  53. )
  54. // NewAuthSource render adding a new auth source page
  55. func NewAuthSource(ctx *context.Context) {
  56. ctx.Data["Title"] = ctx.Tr("admin.auths.new")
  57. ctx.Data["PageIsAdmin"] = true
  58. ctx.Data["PageIsAdminAuthentications"] = true
  59. ctx.Data["type"] = models.LoginLDAP
  60. ctx.Data["CurrentTypeName"] = models.LoginNames[models.LoginLDAP]
  61. ctx.Data["CurrentSecurityProtocol"] = models.SecurityProtocolNames[ldap.SecurityProtocolUnencrypted]
  62. ctx.Data["smtp_auth"] = "PLAIN"
  63. ctx.Data["is_active"] = true
  64. ctx.Data["AuthSources"] = authSources
  65. ctx.Data["SecurityProtocols"] = securityProtocols
  66. ctx.Data["SMTPAuths"] = models.SMTPAuths
  67. ctx.Data["OAuth2Providers"] = models.OAuth2Providers
  68. // only the first as default
  69. for key := range models.OAuth2Providers {
  70. ctx.Data["oauth2_provider"] = key
  71. break
  72. }
  73. ctx.HTML(200, tplAuthNew)
  74. }
  75. func parseLDAPConfig(form auth.AuthenticationForm) *models.LDAPConfig {
  76. return &models.LDAPConfig{
  77. Source: &ldap.Source{
  78. Name: form.Name,
  79. Host: form.Host,
  80. Port: form.Port,
  81. SecurityProtocol: ldap.SecurityProtocol(form.SecurityProtocol),
  82. SkipVerify: form.SkipVerify,
  83. BindDN: form.BindDN,
  84. UserDN: form.UserDN,
  85. BindPassword: form.BindPassword,
  86. UserBase: form.UserBase,
  87. AttributeUsername: form.AttributeUsername,
  88. AttributeName: form.AttributeName,
  89. AttributeSurname: form.AttributeSurname,
  90. AttributeMail: form.AttributeMail,
  91. AttributesInBind: form.AttributesInBind,
  92. Filter: form.Filter,
  93. AdminFilter: form.AdminFilter,
  94. Enabled: true,
  95. },
  96. }
  97. }
  98. func parseSMTPConfig(form auth.AuthenticationForm) *models.SMTPConfig {
  99. return &models.SMTPConfig{
  100. Auth: form.SMTPAuth,
  101. Host: form.SMTPHost,
  102. Port: form.SMTPPort,
  103. AllowedDomains: form.AllowedDomains,
  104. TLS: form.TLS,
  105. SkipVerify: form.SkipVerify,
  106. }
  107. }
  108. func parseOAuth2Config(form auth.AuthenticationForm) *models.OAuth2Config {
  109. return &models.OAuth2Config{
  110. Provider: form.Oauth2Provider,
  111. ClientID: form.Oauth2Key,
  112. ClientSecret: form.Oauth2Secret,
  113. }
  114. }
  115. // NewAuthSourcePost response for adding an auth source
  116. func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
  117. ctx.Data["Title"] = ctx.Tr("admin.auths.new")
  118. ctx.Data["PageIsAdmin"] = true
  119. ctx.Data["PageIsAdminAuthentications"] = true
  120. ctx.Data["CurrentTypeName"] = models.LoginNames[models.LoginType(form.Type)]
  121. ctx.Data["CurrentSecurityProtocol"] = models.SecurityProtocolNames[ldap.SecurityProtocol(form.SecurityProtocol)]
  122. ctx.Data["AuthSources"] = authSources
  123. ctx.Data["SecurityProtocols"] = securityProtocols
  124. ctx.Data["SMTPAuths"] = models.SMTPAuths
  125. ctx.Data["OAuth2Providers"] = models.OAuth2Providers
  126. hasTLS := false
  127. var config core.Conversion
  128. switch models.LoginType(form.Type) {
  129. case models.LoginLDAP, models.LoginDLDAP:
  130. config = parseLDAPConfig(form)
  131. hasTLS = ldap.SecurityProtocol(form.SecurityProtocol) > ldap.SecurityProtocolUnencrypted
  132. case models.LoginSMTP:
  133. config = parseSMTPConfig(form)
  134. hasTLS = true
  135. case models.LoginPAM:
  136. config = &models.PAMConfig{
  137. ServiceName: form.PAMServiceName,
  138. }
  139. case models.LoginOAuth2:
  140. config = parseOAuth2Config(form)
  141. default:
  142. ctx.Error(400)
  143. return
  144. }
  145. ctx.Data["HasTLS"] = hasTLS
  146. if ctx.HasError() {
  147. ctx.HTML(200, tplAuthNew)
  148. return
  149. }
  150. if err := models.CreateLoginSource(&models.LoginSource{
  151. Type: models.LoginType(form.Type),
  152. Name: form.Name,
  153. IsActived: form.IsActive,
  154. Cfg: config,
  155. }); err != nil {
  156. if models.IsErrLoginSourceAlreadyExist(err) {
  157. ctx.Data["Err_Name"] = true
  158. ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), tplAuthNew, form)
  159. } else {
  160. ctx.Handle(500, "CreateSource", err)
  161. }
  162. return
  163. }
  164. log.Trace("Authentication created by admin(%s): %s", ctx.User.Name, form.Name)
  165. ctx.Flash.Success(ctx.Tr("admin.auths.new_success", form.Name))
  166. ctx.Redirect(setting.AppSubURL + "/admin/auths")
  167. }
  168. // EditAuthSource render editing auth source page
  169. func EditAuthSource(ctx *context.Context) {
  170. ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
  171. ctx.Data["PageIsAdmin"] = true
  172. ctx.Data["PageIsAdminAuthentications"] = true
  173. ctx.Data["SecurityProtocols"] = securityProtocols
  174. ctx.Data["SMTPAuths"] = models.SMTPAuths
  175. ctx.Data["OAuth2Providers"] = models.OAuth2Providers
  176. source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
  177. if err != nil {
  178. ctx.Handle(500, "GetLoginSourceByID", err)
  179. return
  180. }
  181. ctx.Data["Source"] = source
  182. ctx.Data["HasTLS"] = source.HasTLS()
  183. if source.IsOAuth2() {
  184. ctx.Data["CurrentOAuth2Provider"] = models.OAuth2Providers[source.OAuth2().Provider]
  185. }
  186. ctx.HTML(200, tplAuthEdit)
  187. }
  188. // EditAuthSourcePost response for editing auth source
  189. func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
  190. ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
  191. ctx.Data["PageIsAdmin"] = true
  192. ctx.Data["PageIsAdminAuthentications"] = true
  193. ctx.Data["SMTPAuths"] = models.SMTPAuths
  194. ctx.Data["OAuth2Providers"] = models.OAuth2Providers
  195. source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
  196. if err != nil {
  197. ctx.Handle(500, "GetLoginSourceByID", err)
  198. return
  199. }
  200. ctx.Data["Source"] = source
  201. ctx.Data["HasTLS"] = source.HasTLS()
  202. if ctx.HasError() {
  203. ctx.HTML(200, tplAuthEdit)
  204. return
  205. }
  206. var config core.Conversion
  207. switch models.LoginType(form.Type) {
  208. case models.LoginLDAP, models.LoginDLDAP:
  209. config = parseLDAPConfig(form)
  210. case models.LoginSMTP:
  211. config = parseSMTPConfig(form)
  212. case models.LoginPAM:
  213. config = &models.PAMConfig{
  214. ServiceName: form.PAMServiceName,
  215. }
  216. case models.LoginOAuth2:
  217. config = parseOAuth2Config(form)
  218. default:
  219. ctx.Error(400)
  220. return
  221. }
  222. source.Name = form.Name
  223. source.IsActived = form.IsActive
  224. source.Cfg = config
  225. if err := models.UpdateSource(source); err != nil {
  226. ctx.Handle(500, "UpdateSource", err)
  227. return
  228. }
  229. log.Trace("Authentication changed by admin(%s): %d", ctx.User.Name, source.ID)
  230. ctx.Flash.Success(ctx.Tr("admin.auths.update_success"))
  231. ctx.Redirect(setting.AppSubURL + "/admin/auths/" + com.ToStr(form.ID))
  232. }
  233. // DeleteAuthSource response for deleting an auth source
  234. func DeleteAuthSource(ctx *context.Context) {
  235. source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
  236. if err != nil {
  237. ctx.Handle(500, "GetLoginSourceByID", err)
  238. return
  239. }
  240. if err = models.DeleteSource(source); err != nil {
  241. if models.IsErrLoginSourceInUse(err) {
  242. ctx.Flash.Error(ctx.Tr("admin.auths.still_in_used"))
  243. } else {
  244. ctx.Flash.Error(fmt.Sprintf("DeleteSource: %v", err))
  245. }
  246. ctx.JSON(200, map[string]interface{}{
  247. "redirect": setting.AppSubURL + "/admin/auths/" + ctx.Params(":authid"),
  248. })
  249. return
  250. }
  251. log.Trace("Authentication deleted by admin(%s): %d", ctx.User.Name, source.ID)
  252. ctx.Flash.Success(ctx.Tr("admin.auths.deletion_success"))
  253. ctx.JSON(200, map[string]interface{}{
  254. "redirect": setting.AppSubURL + "/admin/auths",
  255. })
  256. }