(c *context.Context, f form.Authentication)
| 115 | } |
| 116 | |
| 117 | func NewAuthSourcePost(c *context.Context, f form.Authentication) { |
| 118 | c.Title("admin.auths.new") |
| 119 | c.PageIs("Admin") |
| 120 | c.PageIs("AdminAuthentications") |
| 121 | |
| 122 | c.Data["CurrentTypeName"] = auth.Name(auth.Type(f.Type)) |
| 123 | c.Data["CurrentSecurityProtocol"] = ldap.SecurityProtocolName(ldap.SecurityProtocol(f.SecurityProtocol)) |
| 124 | c.Data["AuthSources"] = authSources |
| 125 | c.Data["SecurityProtocols"] = securityProtocols |
| 126 | c.Data["SMTPAuths"] = smtp.AuthTypes |
| 127 | |
| 128 | hasTLS := false |
| 129 | var config any |
| 130 | switch auth.Type(f.Type) { |
| 131 | case auth.LDAP, auth.DLDAP: |
| 132 | config = parseLDAPConfig(f) |
| 133 | hasTLS = ldap.SecurityProtocol(f.SecurityProtocol) > ldap.SecurityProtocolUnencrypted |
| 134 | case auth.SMTP: |
| 135 | config = parseSMTPConfig(f) |
| 136 | hasTLS = true |
| 137 | case auth.PAM: |
| 138 | config = &pam.Config{ |
| 139 | ServiceName: f.PAMServiceName, |
| 140 | } |
| 141 | case auth.GitHub: |
| 142 | config = &github.Config{ |
| 143 | APIEndpoint: strings.TrimSuffix(f.GitHubAPIEndpoint, "/") + "/", |
| 144 | SkipVerify: f.SkipVerify, |
| 145 | } |
| 146 | hasTLS = true |
| 147 | default: |
| 148 | c.Status(http.StatusBadRequest) |
| 149 | return |
| 150 | } |
| 151 | c.Data["HasTLS"] = hasTLS |
| 152 | |
| 153 | if c.HasError() { |
| 154 | c.HTML(http.StatusBadRequest, tmplAdminAuthNew) |
| 155 | return |
| 156 | } |
| 157 | |
| 158 | source, err := database.Handle.LoginSources().Create(c.Req.Context(), |
| 159 | database.CreateLoginSourceOptions{ |
| 160 | Type: auth.Type(f.Type), |
| 161 | Name: f.Name, |
| 162 | Activated: f.IsActive, |
| 163 | Default: f.IsDefault, |
| 164 | Config: config, |
| 165 | }, |
| 166 | ) |
| 167 | if err != nil { |
| 168 | if database.IsErrLoginSourceAlreadyExist(err) { |
| 169 | c.FormErr("Name") |
| 170 | c.RenderWithErr(c.Tr("admin.auths.login_source_exist", f.Name), http.StatusUnprocessableEntity, tmplAdminAuthNew, f) |
| 171 | } else { |
| 172 | c.Error(err, "create login source") |
| 173 | } |
| 174 | return |
nothing calls this directly
no test coverage detected