예제 #1
0
 public static AuthenticationProperties CreateProperties(ApplicationUser user)
 {
     IDictionary<string, string> data = new Dictionary<string, string>
     {
         { "userName", user.UserName },
         { "realName", user.RealName ?? "" },
         { "houseId", user.HouseId.IfNotNull(i => i.ToString()) ?? ""   },
         { "id", user.Id}
     };
     return new AuthenticationProperties(data);
 }
예제 #2
0
파일: UserHelpers.cs 프로젝트: DaveWM/Abode
 // check if the currently logged in user can view another user (can only view user in same house)
 public static void VerifyViewableUser(ApplicationUser user)
 {
     if (user == null)
     {
         throw new HttpResponseException(HttpStatusCode.BadRequest);
     }
     else if (user.HouseId != UserHelpers.GetCurrentUser().HouseId) // not in same house as current user
     {
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
 }
예제 #3
0
        private async Task<bool> RegisterExternal(RegisterExternalBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                throw new ValidationException("Error validating the registration model");
            }

            var info = await Authentication.GetExternalLoginInfoAsync();
            if (info == null)
            {
                throw new AuthenticationException("GetExternalLoginInfoAsync() failed");
            }

            var user = new ApplicationUser()
                       {
                           UserName = model.Email,
                           Email = model.Email,
                           RealName = model.RealName,
                           PhoneNumber = model.PhoneNumber
                       };
            IdentityResult result = await UserManager.CreateAsync(user);
            if (!result.Succeeded)
            {
                throw new Exception(string.Format("Errors: {0}", String.Join(", ", result.Errors)));
            }

            result = await UserManager.AddLoginAsync(user.Id, info.Login);
            if (!result.Succeeded)
            {
                throw new Exception(string.Format("Errors: {0}", String.Join(", ", result.Errors)));
            }
            return true;
        }
예제 #4
0
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var user = new ApplicationUser() { UserName = model.Email, Email = model.Email, RealName = model.Name };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            return Ok();
        }