Example #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);
 }
Example #2
0
 // 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);
     }
 }
Example #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;
        }
Example #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();
        }