示例#1
0
        public async Task <HttpResponseMessage> Login(LoginDto request)
        {
            try
            {
                var auth0Domain       = ConfigurationManager.AppSettings["Auth0Domain"];
                var auth0ClientId     = ConfigurationManager.AppSettings["Auth0ClientId"];
                var auth0ClientSecret = ConfigurationManager.AppSettings["Auth0ClientSecret"];

                AuthenticationApiClient client =
                    new AuthenticationApiClient(
                        new Uri($"https://{auth0Domain}/"));

                //Get the auth token from auth0 login endpoint
                var result = await client.GetTokenAsync(new ResourceOwnerTokenRequest
                {
                    ClientId     = auth0ClientId,
                    ClientSecret = auth0ClientSecret,
                    Scope        = "openid",
                    Audience     = "http://smartdatatest.com/",
                    Realm        = "Username-Password-Authentication", // Specify the correct name of your DB connection
                    Username     = request.Username,
                    Password     = request.Password
                });

                return(Request.CreateResponse(HttpStatusCode.OK, result.AccessToken));
            }
            catch (Exception e)
            {
                SmartApartmentLogger.LogAsync(ELogType.Error, e.Message, "ErrorCode:222");
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse(222, e.Message)));
            }
        }
示例#2
0
        public async Task <HttpResponseMessage> ResetPassword(ResetPasswordRequest request)
        {
            try
            {
                var apiRequest = new APIRequest(RequestMethod.POST,
                                                $"https://{ConfigurationManager.AppSettings["Auth0Domain"]}/dbconnections/change_password")
                {
                    RequestHeaders    = new Dictionary <string, string>(),
                    RequestParameters = new Dictionary <string, string>()
                    {
                        { "client_id", ConfigurationManager.AppSettings["Auth0ClientId"] },
                        { "email", request.Username },
                        { "connection", "Username-Password-Authentication" }
                    }
                };

                var apiResponse = await _apiService.SendRequestAsync(apiRequest);

                if (apiResponse.Success)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, apiResponse.Response));
                }

                return(Request.CreateResponse(apiResponse.StatusCode, apiResponse.Response));
            }
            catch (Exception e)
            {
                SmartApartmentLogger.LogAsync(ELogType.Error, e.Message);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                              new ErrorResponse(500, "Internal server error. Please try again later")));
            }
        }
示例#3
0
 public HttpResponseMessage AddGuild(GuildModelDto request)
 {
     try
     {
         _dataAccess.AddGuild(request);
         var getPlayer =
             _dataAccess.GetPlayerByUserId(((UserModel)ActionContext.Request.Properties["user"]).Id);
         _dataAccess.AddGuildMember(getPlayer.Name, request.Name);
         return(Request.CreateResponse(HttpStatusCode.OK, "Guild successfully added"));
     }
     catch (PlayerNotFoundException playerNotFoundException)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(PlayerNotFoundException.ERROR_CODE, playerNotFoundException.Message)));
     }
     catch (GuildNotFoundException guildNotFoundException)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(GuildNotFoundException.ERROR_CODE, guildNotFoundException.Message)));
     }
     catch (FactionNotFoundException factionNotFoundException)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(FactionNotFoundException.ERROR_CODE, factionNotFoundException.Message)));
     }
     catch (Exception e)
     {
         SmartApartmentLogger.LogAsync(ELogType.Error, e.Message);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(500, "Internal server error. Please try again later")));
     }
 }
        public HttpResponseMessage DeleteRace(DeleteRaceRequest request)
        {
            try
            {
                if (request.Id.HasValue)
                {
                    _dataAccess.DeleteRaceByID(request.Id.Value);
                }
                else if (!request.Name.Equals(string.Empty))
                {
                    _dataAccess.DeleteFactionByName(request.Name);
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (RaceNotFoundException raceNotFoundException)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse(RaceNotFoundException.ERROR_CODE, raceNotFoundException.Message)));
            }
            catch (Exception e)
            {
                SmartApartmentLogger.LogAsync(ELogType.Error, e.Message);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse(500, "Internal server error. Please try again later")));
            }
        }
 public HttpResponseMessage AddPlayer(PlayerModelDto request)
 {
     try
     {
         _dataAccess.AddPlayer(request, ((UserModel)ActionContext.Request.Properties["user"]).Id);
         return(Request.CreateResponse(HttpStatusCode.OK, "Player successfully added"));
     }
     catch (ClassNotFoundException classNotFoundException)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(ClassNotFoundException.ERROR_CODE, classNotFoundException.Message)));
     }
     catch (FactionNotFoundException factionNotFoundException)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(FactionNotFoundException.ERROR_CODE, factionNotFoundException.Message)));
     }
     catch (RaceNotFoundException raceNotFoundException)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(RaceNotFoundException.ERROR_CODE, raceNotFoundException.Message)));
     }
     catch (PlayerAlreadyExistsException playerAlreadyExistsException)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(PlayerAlreadyExistsException.ERROR_CODE, playerAlreadyExistsException.Message)));
     }
     catch (Exception e)
     {
         SmartApartmentLogger.LogAsync(ELogType.Error, e.Message);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(500, "Internal server error. Please try again later")));
     }
 }
 public HttpResponseMessage GetRaceByName(string name)
 {
     try
     {
         return(Request.CreateResponse(HttpStatusCode.OK, _dataAccess.GetRaceByName(name)));
     }
     catch (Exception e)
     {
         SmartApartmentLogger.LogAsync(ELogType.Error, e.Message);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse(500, e.Message)));
     }
 }
 public HttpResponseMessage AddRace(RaceModelDto request)
 {
     try
     {
         _dataAccess.AddRace(request);
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
     catch (Exception exception)
     {
         SmartApartmentLogger.LogAsync(ELogType.Error, exception.Message);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(500, "Internal server error. Please try again later")));
     }
 }
 public HttpResponseMessage GetPlayerByName(string name)
 {
     try
     {
         var playerModel = _dataAccess.GetPlayerByName(name);
         return(Request.CreateResponse(HttpStatusCode.OK, playerModel));
     }
     catch (Exception e)
     {
         SmartApartmentLogger.LogAsync(ELogType.Error, e.Message);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(500, "Internal server error. Please try again later")));
     }
 }
 public HttpResponseMessage GetClassById(int id)
 {
     try
     {
         return(Request.CreateResponse(HttpStatusCode.OK, _dataAccess.GetClassByID(id)));
     }
     catch (ClassNotFoundException classNotFoundException)
     {
         SmartApartmentLogger.LogAsync(ELogType.Debug, classNotFoundException.Message, $"ErrorCode:{ClassNotFoundException.ERROR_CODE}");
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(ClassNotFoundException.ERROR_CODE, classNotFoundException.Message)));
     }
     catch (Exception e)
     {
         SmartApartmentLogger.LogAsync(ELogType.Error, e.Message);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse(500, e.Message)));
     }
 }
示例#10
0
 public HttpResponseMessage GetGuildMembers(string guildName)
 {
     try
     {
         var getGuildMembers = _dataAccess.GetGuildMembers(guildName);
         return(Request.CreateResponse(HttpStatusCode.OK, getGuildMembers));
     }
     catch (GuildNotFoundException guildNotFoundException)
     {
         SmartApartmentLogger.LogAsync(ELogType.Debug, "Test");
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(GuildNotFoundException.ERROR_CODE, guildNotFoundException.Message)));
     }
     catch (Exception e)
     {
         SmartApartmentLogger.LogAsync(ELogType.Error, e.Message);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(500, "Internal server error. Please try again later")));
     }
 }
示例#11
0
 public HttpResponseMessage AddGuildMember(AddGuildMemberRequest request)
 {
     try
     {
         _dataAccess.AddGuildMember(request.PlayerName, request.GuildName);
         return(Request.CreateResponse(HttpStatusCode.OK, "Player successfully added to the guild"));
     }
     catch (PlayerNotFoundException playerNotFoundException)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(PlayerNotFoundException.ERROR_CODE, playerNotFoundException.Message)));
     }
     catch (GuildNotFoundException guildNotFoundException)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(GuildNotFoundException.ERROR_CODE, guildNotFoundException.Message)));
     }
     catch (Exception e)
     {
         SmartApartmentLogger.LogAsync(ELogType.Error, e.Message);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                       new ErrorResponse(500, "Internal server error. Please try again later")));
     }
 }