コード例 #1
0
        /// <summary>
        /// Create a Login resource.
        /// </summary>
        /// <param name="user">the user to log in</param>
        /// <param name="baseAddress">the host to log into</param>
        /// <param name="lang">the culture to retrieve login info into (fr-FR or en-US)</param>
        /// <returns>a login object with credential headers and a User with its Clients</returns>
        public async static Task <object> Login(User user, string baseAddress, string lang)
        {
            if (user == null || user.Password == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            CulturalEnumStringConverter.Culture = new CultureInfo(lang);

            string hashedPassword = HashManager.GetHash(user.Password);

            user.Password = hashedPassword;
            User seekedUser = await _findUser(user.Login);

            if (seekedUser == null || hashedPassword != seekedUser.Password)
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            await _removeLogout(seekedUser.Login);

            Random r1 = new Random(159736545);
            Random r2 = new Random(1892344171);

            seekedUser.Password = null;
            return(new
            {
                a2un = string.Format("{0}.{1}.{2}", string.Format("{0:X12}", r1.Next(0x5F4A2C3)), string.Format("{0:X18}", r1.Next(0x5FDA6C1)), string.Format("{0:X22}", r1.Next(0x5F1C2C3))),
                az4s = JsonWebTokenManager.CreateToken(user.Login, "user", baseAddress),
                e7gu = string.Format("{0}.{1}.{2}", string.Format("{0:X12}", r2.Next(0x5F4A2C3)), string.Format("{0:X18}", r2.Next(0x5FDA6C1)), string.Format("{0:X22}", r2.Next(0x5F1C2C3))),
                user = seekedUser,
                ranges = await RangeService.GetAllRanges(lang)
            });
        }
コード例 #2
0
 private async static Task <Range> _searchRange(int rangeId, string lang)
 {
     return(await RangeService.GetRange(rangeId, lang));
 }