private bool Authenticate(FotoShoutData.Models.Credentials credential) { try { FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Authenticating for the \"{0}\" user...", credential.Email)); User = _fsWebService.Login(credential); if (User == null) { FotoShoutUtils.Log.LogManager.Error(_logger, "Unexpected error - There is no user on the central fotoShout associated with the fotoShout Authorization key.\r\n"); return(false); } FotoShoutUtils.Log.LogManager.Info(_logger, "Succeeded logged"); FotoShoutUtils.Log.LogManager.Info(_logger, "Getting publish configuration information..."); PublishAccount publishAccount = _fsWebService.GetPublishConfiguration(); if (publishAccount != null && !string.IsNullOrEmpty(publishAccount.Url)) { string url = publishAccount.Url.EndsWith("/") ? publishAccount.Url.Substring(0, publishAccount.Url.Length - 1) : publishAccount.Url; int lastIdx = url.LastIndexOf("/"); if (lastIdx != -1) { string baseAddress = url.Substring(0, lastIdx + 1); string prefix = url.Substring(lastIdx + 1); _c9WebService = new PublishApiWebService(baseAddress, prefix, FotoShoutUtils.Constants.MEDIATYPE_APPLICATION_JSON); string ret = _c9WebService.Authenticate(publishAccount.ApiKey.ToString(), new LoginModel { UserName = publishAccount.Email, Password = publishAccount.Password }); if (string.IsNullOrEmpty(ret)) { FotoShoutUtils.Log.LogManager.Error(_logger, "Unable to authorize to the publishing API.\r\n"); return(false); } } else { FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Unable to authorize to the publishing API - The \"{0}\" url is incorrect.\r\n", publishAccount.Url)); return(false); } } else { FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("There is no publish configuration for the \"{0}\" user.\r\n", publishAccount.Url)); return(false); } FotoShoutUtils.Log.LogManager.Info(_logger, "Successfully authenticated.\r\n"); return(true); } catch (HttpClientServiceException ex) { FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Failed to authenticate : {0} (Status Code: {1})\r\n", ex.Message, (int)ex.StatusCode)); } catch (Exception ex) { FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Failed to authenticate: {0}\r\n", ex.ToString())); } return(false); }
private bool Login(LoginModel model) { UserTDO user = _fsWebService.Login(AppConfigs.ApiKey, model); if (user != null) { Response.SetAuthCookie <string>(user.FirstName + " " + user.LastName, model.RememberMe, _fsWebService.Authorization); return(true); } return(false); }
private bool InitializeApi(FsApiWebService fsApiService, bool serverAuthenticated) { if (serverAuthenticated) { if (User != null) { return(true); } } else if (ClientUser != null) { return(true); } LoginModel model = new LoginModel { UserName = AppConfig.FsUserEmail, Password = AppConfig.FsPassword }; UserTDO user = null; try { FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Authorizing for fotoShout on {0}...", fsApiService.BaseAddress)); user = fsApiService.Login(AppConfig.FsApiKey, model); if (user == null) { FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("There is no user on {0} associated with the fotoShout Authorization key. The authentication will be retried in the next round.", fsApiService.BaseAddress)); return(false); } FotoShoutUtils.Log.LogManager.Info(_logger, "Succeeded to access to the user info."); } catch (Exception ex) { if (ex is WebException) { FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Exception on {0}: {1}.", fsApiService.BaseAddress, ex.Message)); } else { FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("There is no user on {0} associated with the fotoShout Authorization key. The authentication will be retried in the next round.", fsApiService.BaseAddress)); } return(false); } if (serverAuthenticated) { User = user; } else { ClientUser = user; } return(true); }