Exemple #1
0
 private Response GetGravatarImage()
 {
     if (LoggedIn)
     {
         var user   = UserHelper.GetUser(Username);
         var hashed = StringHasher.CalcuateMd5Hash(user.EmailAddress);
         if (string.IsNullOrEmpty(hashed))
         {
             return(Response.AsJson(new JsonResponseModel
             {
                 Result = false
             }));
         }
         return
             (Response.AsJson(new JsonResponseModel
         {
             Result = true,
             Message = $"https://www.gravatar.com/avatar/{hashed}"
         }));
     }
     else
     {
         return(Response.AsJson(new JsonResponseModel {
             Result = false
         }));
     }
 }
Exemple #2
0
        public EmbyUser LogIn(string username, string password, string apiKey, Uri baseUri)
        {
            var request = new RestRequest
            {
                Resource = "emby/users/authenticatebyname",
                Method   = Method.POST
            };

            var body = new
            {
                username,
                password    = StringHasher.GetSha1Hash(password).ToLower(),
                passwordMd5 = StringHasher.CalcuateMd5Hash(password)
            };

            request.AddJsonBody(body);

            request.AddHeader("X-Emby-Authorization",
                              $"MediaBrowser Client=\"Ombi\", Device=\"Ombi\", DeviceId=\"{AssemblyHelper.GetProductVersion()}\", Version=\"{AssemblyHelper.GetAssemblyVersion()}\"");
            AddHeaders(request, apiKey);


            var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling LogInfor Emby, Retrying {0}", timespan), new[] {
                TimeSpan.FromSeconds(1)
            });

            var obj = policy.Execute(() => Api.Execute(request, baseUri));

            if (obj.StatusCode == HttpStatusCode.Unauthorized)
            {
                return(null);
            }

            return(JsonConvert.DeserializeObject <EmbyUserLogin>(obj.Content)?.User);
        }
Exemple #3
0
        public CouchPotatoApiKey GetApiKey(Uri baseUrl, string username, string password)
        {
            var request = new RestRequest
            {
                Resource = "getkey/?u={username}&p={password}",
                Method   = Method.GET
            };

            request.AddUrlSegment("username", StringHasher.CalcuateMd5Hash(username));
            request.AddUrlSegment("password", StringHasher.CalcuateMd5Hash(password));

            var obj = RetryHandler.Execute(() => Api.Execute <CouchPotatoApiKey>(request, baseUrl),
                                           (exception, timespan) => Log.Error(exception, "Exception when calling GetApiKey for CP, Retrying {0}", timespan), null);

            return(obj);
        }
Exemple #4
0
 public string CalcuateMd5HashTest(string input)
 {
     return(StringHasher.CalcuateMd5Hash(input));
 }