예제 #1
0
        public bool SearchPersonaId(string userId, out AtomUser user)
        {
            userClient.AuthToken = OriginToken;

            var atomUsers = GetAtomUsers(new List <InfoList> {
                new InfoList {
                    friendUserId = userId
                }
            });

            user = atomUsers.Users.FirstOrDefault();
            if (atomUsers.Users.Count == 1)
            {
                user.Avatar = GetAvatar(user.UserId);
                return(true);
            }

            return(false);
        }
예제 #2
0
파일: Auth.cs 프로젝트: Razer2015/BattleAPI
        /// <summary>
        /// Search for PersonaId based on Username
        /// </summary>
        /// <param name="searchTerm">Username to search for (be specific)</param>
        /// <param name="user">Result user (if any)</param>
        /// <param name="status">Status of the search</param>
        /// <returns>Success/Fail</returns>
        public bool SearchPersonaId(string searchTerm, out AtomUser user, out UserSearchStatus status)
        {
            userClient.AuthToken = OriginToken;
            var result   = userClient.DownloadString($"{API}/xsearch/users?userId={_myself.pid.pidId}&searchTerm={searchTerm}");
            var personas = JsonConvert.DeserializeObject <Personas>(result);

            user = null;
            //if (personas.totalCount > 20) {
            //    status = UserSearchStatus.TOO_MANY_RESULTS;
            //    return false;
            //}
            //else if (personas.totalCount <= 0) {
            //    status = UserSearchStatus.NO_MATCHES;
            //    return false;
            //}
            if (personas.totalCount <= 0)
            {
                status = UserSearchStatus.NO_MATCHES;
                return(false);
            }

            //result = userClient.DownloadString($"{API}/atom/users?userIds={string.Join(",", personas.infoList.Select(x => x.friendUserId))}");
            //var atomUsers = new XMLSerializer().Deserialize<AtomUsers>(result);
            // Apparently 5 at a time is a max
            var atomUsers = GetAtomUsers(personas.infoList);

            user = atomUsers.Users.FirstOrDefault(x => x.EAID.Equals(searchTerm, StringComparison.OrdinalIgnoreCase));
            if (user != null)
            {
                status      = UserSearchStatus.SUCCESS;
                user.Avatar = GetAvatar(user.UserId);
                return(true);
            }
            else
            {
                status = UserSearchStatus.PARTIAL_MATCHES;
                return(false);
            }
        }
예제 #3
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new AtomUser() { UserName = model.UserName };
                user.ProfileId = "PROFXXXXX";
                user.FirstName = "Junel";
                user.LastName = "Corales";
                user.Email = "*****@*****.**";

                user.Courses = new HashSet<AtomUserCourse>();
                user.Courses.Add(new AtomUserCourse
                {
                    CourseAccessId = "COURSE1XXX",
                    AtomUser = user,
                    AtomUserId = user.Id
                });
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #4
0
 private async Task SignInAsync(AtomUser user, bool isPersistent)
 {
     AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
     var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
     AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
 }
예제 #5
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new AtomUser() { UserName = model.UserName };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInAsync(user, isPersistent: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }