public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } ExternalLoginData externalLogin = ExternalLoginData.FromIdentity(User.Identity as ClaimsIdentity); if (externalLogin == null) { return InternalServerError(); } SkillsmartUser user = new SkillsmartUser { UserName = model.email }; user.AddClaims(model.firstName, model.lastName); user.Roles.Add(UserRole.Member.ToString()); user.Logins.Add(new UserLoginInfo(externalLogin.LoginProvider, externalLogin.ProviderKey)); IdentityResult result = await UserManager.CreateAsync(user); IHttpActionResult errorResult = GetErrorResult(result); if (errorResult != null) { return errorResult; } return Ok(); }
public static AuthenticationProperties CreateProperties(SkillsmartUser user) { if (user != null) { IDictionary<string, string> data = new Dictionary<string, string> { { "userName", user.UserName }, { "email", user.UserName}, { "firstName", user.ClaimValue(SkillsmartUser.FirstName)}, { "lastName", user.ClaimValue(SkillsmartUser.LastName)} }; return new AuthenticationProperties(data); } return new AuthenticationProperties(new Dictionary<string, string>()); }
public async Task<IHttpActionResult> Register(RegisterBindingModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } SkillsmartUser user = new SkillsmartUser { UserName = model.email }; user.Claims.Add(new MongoDB.AspNet.Identity.IdentityUserClaim { ClaimType = SkillsmartUser.SkillSmartId, ClaimValue = Guid.NewGuid().ToString() }); user.Claims.Add(new MongoDB.AspNet.Identity.IdentityUserClaim { ClaimType = SkillsmartUser.FirstName, ClaimValue = model.firstName }); user.Claims.Add(new MongoDB.AspNet.Identity.IdentityUserClaim { ClaimType = SkillsmartUser.LastName, ClaimValue = model.lastName }); user.Roles.Add(UserRole.Member.ToString()); IdentityResult result = await UserManager.CreateAsync(user, model.password); IHttpActionResult errorResult = GetErrorResult(result); if (errorResult != null) { return errorResult; } return Ok(); }