private void Load(UserData user) { Username = user.UserName; if (user.GetPicture() != null && user.PictureType != null && user.GetPicture().Length > 0 && user.PictureType.Length > 0) { Input = new IdentityProfile { FirstName = user.FirstName, MiddleName = user.MiddleName, LastName = user.LastName, Gender = user.Gender, BirthDate = user.BirthDate, ViewPicture = string.Format(CultureInfo.InvariantCulture, "data:{0};base64,{1}", user.PictureType, Convert.ToBase64String(user.GetPicture())), PhoneNumber = user.PhoneNumber }; } else { Input = new IdentityProfile { FirstName = user.FirstName, MiddleName = user.MiddleName, LastName = user.LastName, Gender = user.Gender, BirthDate = user.BirthDate, PhoneNumber = user.PhoneNumber }; } }
public async Task <IdentityResult> Update(IdentityProfile profile, string userName) { var user = await accountManager.FindByNameAsync(userName); if (user.Type == IdentityTypes.USER && profile.GetType() != typeof(UserProfile)) { throw new InvalidOperationException("Updating User with different payload"); } else if (user.Type == IdentityTypes.ENTERPRISE && profile.GetType() != typeof(EnterpriseUserProfile)) { throw new InvalidOperationException("Updating Enterprise user with different payload"); } else if (user.Type != IdentityTypes.USER || user.Type != IdentityTypes.ENTERPRISE && profile.GetType() != typeof(AssetProfile)) { // INFO: Not changing pic url this way. :) // Would have a seperate update method, this shouldnt affect the PicUri profile.PicUri = user.Profile.PicUri; } user.Profile = profile; var result = await accountManager.UpdateAsync(user); userUpdateSubject?.OnNext(user); return(result); }
public async Task <ActionResult <IdentityProfile> > AddClaims(string id, [FromBody] IEnumerable <MyClaim> claims) { IdentityProfile user = await _userManager.FindByIdAsync(id); await _userManager.AddClaimsAsync(user, claims.Select(c => new Claim(c.Type, c.Value))); return(user); }
public async Task <IHttpActionResult> Put(Guid Useraccountid, [FromBody] IdentityProfile model) { if (model.Useraccountid != Useraccountid) { return(BadRequest("Resource Useraccountid's do not match.")); } model.AppendTransactionContext(Request); return(await Save(model)); }
public async Task <IHttpActionResult> Get(Guid Useraccountid) { IdentityProfile item = await _bl.GetByKeyAsync(Useraccountid); if (item.Useraccountid == Useraccountid) { return(Ok(item)); } return(NotFound()); }
public async Task <bool> DeleteById(Guid id) { IdentityProfile user = await _userManager.FindByIdAsync(id.ToString()); if (user == null) { return(false); } return((await _userManager.DeleteAsync(user)).Succeeded); }
private async Task <IHttpActionResult> Save(IdentityProfile model) { model = await _bl.SaveAsync(model); if (model.Validation.IsValid) { return(Ok(model)); } CreateModelState(model.Validation); return(BadRequest(ModelState)); }
public async Task <IHttpActionResult> List([FromUri] IdentityProfile filter, [FromUri] PageConfig pageConfig) { if (pageConfig == null) { pageConfig = new PageConfig(); } if (filter == null) { filter = new IdentityProfile(); } return(Ok(await _bl.List(filter, pageConfig))); }
public UserModel(User user, bool isUserAuthenticated = false) { this.UserId = user.Id; this.Type = user.Type; this.PhoneNumber = user.PhoneNumber; this.PhoneNumberConfirmed = user.PhoneNumberConfirmed; this.Email = user.Email; this.EmailConfirmed = user.EmailConfirmed; this.Profile = user.GetType() == typeof(User) ? user.Profile : null; this.UserName = user.UserName; this.IsUserAuthenticated = isUserAuthenticated; }
public async Task <bool> Create(Profile profile, string password) { var user = new IdentityProfile(profile.UserName) { Email = profile.Email, PhoneNumber = profile.PhoneNumber, FirstName = profile.FirstName, LastName = profile.LastName, UserName = profile.UserName, Birthday = profile.Birthday, }; return((await _userManager.CreateAsync(user, password)).Succeeded); }
public async Task <IdentityResult> UpdateById(IdentityProfile model, string userId) { var user = await accountManager.FindByIdAsync(userId); // INFO: Not changing pic url this way. :) // Would have a seperate update method, this shouldnt affect the PicUri model.PicUri = user.Profile.PicUri; user.Profile = model; var result = await accountManager.UpdateAsync(user); userUpdateSubject?.OnNext(user); return(result); }
public async Task <IHttpActionResult> Delete(Guid Useraccountid, [FromBody] IdentityProfile model) { if (model.Useraccountid != Useraccountid) { return(BadRequest("Resource Useraccountid's do not match.")); } model.AppendTransactionContext(Request); model = await _bl.DeleteAsync(model); if (model.Validation.IsValid) { return(Ok(model)); } CreateModelState(model.Validation); return(BadRequest(ModelState)); }
public async Task <bool> Update(Profile profile) { IdentityProfile user = await _userManager.FindByIdAsync(profile.Id.ToString()); if (user == null) { return(false); } user.Email = profile.Email ?? user.Email; user.Birthday = profile.Birthday ?? user.Birthday; user.FirstName = profile.FirstName ?? user.FirstName; user.LastName = profile.LastName ?? user.LastName; user.PhoneNumber = profile.PhoneNumber ?? user.PhoneNumber; user.UserName = profile.UserName ?? user.UserName; return((await _userManager.UpdateAsync(user)).Succeeded); }
public async Task Invoke(HttpContext context) { string token = context.Request.Headers["Authorization"]; if (!string.IsNullOrEmpty(token)) { token = token.Replace("Bearer", ""); token = token.Replace("bearer", ""); token = token.Trim(); IdentityServerCall identityServerCall = new IdentityServerCall(); IdentityResponseModel responseBody = await identityServerCall.ValidateToken(token, identityClientModel.IdentityServerUrl); context.Response.ContentType = "application/json"; if (responseBody.code != "IDS00") { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; await context.Response.WriteAsync(JsonConvert.SerializeObject(responseBody, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore })); } else { IdentityProfile identityProfile = responseBody.data;// JsonConvert.DeserializeObject<IdentityProfile>(responseBody.data); List <ClaimsIdentity> claims = new List <ClaimsIdentity>() { new ClaimsIdentity(new List <Claim>() { new Claim(ClaimTypes.NameIdentifier, identityProfile.Id), new Claim(ClaimTypes.Authentication, "true"), new Claim(ClaimTypes.Email, string.IsNullOrEmpty(identityProfile.email)?string.Empty:identityProfile.email), new Claim(ClaimTypes.MobilePhone, string.IsNullOrEmpty(identityProfile.phoneNumber)? string.Empty: identityProfile.phoneNumber), new Claim(ClaimTypes.Name, $"{identityProfile.lastName} {identityProfile.otherNames??string.Empty}"), new Claim(ClaimTypes.Surname, identityProfile.lastName) }, "Basic") }; context.User = new ClaimsPrincipal(claims); await next(context); } } else { await next(context); } }
protected User(RegistrationModelBase model, IdentityProfile profile): this(model) { this.Profile = profile; }
public async Task<IHttpActionResult> Update(IdentityProfile model) { return Ok(await accountContext.Update(model, this.User.Identity.Name)); }
public async Task<IdentityResult> UpdateById(IdentityProfile model, string userId) { var user = await accountManager.FindByIdAsync(userId); // INFO: Not changing pic url this way. :) // Would have a seperate update method, this shouldnt affect the PicUri model.PicUri = user.Profile.PicUri; user.Profile = model; return await accountManager.UpdateAsync(user); }
public async Task <IHttpActionResult> Post([FromBody] IdentityProfile model) { model.AppendTransactionContext(Request); return(await Save(model)); }
public async Task <Profile> GetById(Guid id) { IdentityProfile user = await _userManager.FindByIdAsync(id.ToString()); return(new Profile(user)); }
public async Task <IHttpActionResult> Update([FromBody] IdentityProfile model, [FromUri] string id) { return(Ok(await accountContext.UpdateById(model, id))); }
public async Task <IHttpActionResult> Update(IdentityProfile model) { return(Ok(await accountContext.Update(model, this.User.Identity.Name))); }
public async Task<IdentityResult> Update(IdentityProfile profile, string userName) { var user = await accountManager.FindByNameAsync(userName); if (user.Type == IdentityTypes.USER && profile.GetType() != typeof(UserProfile)) throw new InvalidOperationException("Updating User with different payload"); else if (user.Type == IdentityTypes.ENTERPRISE && profile.GetType() != typeof(EnterpriseUserProfile)) throw new InvalidOperationException("Updating Enterprise user with different payload"); else if (user.Type != IdentityTypes.USER || user.Type != IdentityTypes.ENTERPRISE && profile.GetType() != typeof(AssetProfile)) // INFO: Not changing pic url this way. :) // Would have a seperate update method, this shouldnt affect the PicUri profile.PicUri = user.Profile.PicUri; user.Profile = profile; var result = await accountManager.UpdateAsync(user); if (user.Type != IdentityTypes.USER && user.Type != IdentityTypes.ENTERPRISE) { var updateDef = Builders<Job>.Update.Set(x => x.Assets[user.Id], new AssetModel(user as Asset)); var searchFilter = Builders<Job>.Filter.Exists(x => x.Assets[user.Id], true); var propagationResult = await dbContext.Jobs.UpdateManyAsync(searchFilter, updateDef); } else if (user.Roles.Any(x => x == "Administrator" || x == "BackOfficeAdmin")) { var userModel = new UserModel(user); var updateDef = Builders<Job>.Update.Set(x => x.JobServedBy, userModel); var searchFilter = Builders<Job>.Filter.Where(x => x.JobServedBy.UserId == user.Id); var propagationResult = await dbContext.Jobs.UpdateManyAsync(searchFilter, updateDef); } else if (user.Type == IdentityTypes.USER && user.Type == IdentityTypes.ENTERPRISE) { var userModel = user.Type == IdentityTypes.USER ? new UserModel(user) : new EnterpriseUserModel(user as EnterpriseUser); var updateDef = Builders<Job>.Update.Set(x => x.User, userModel); var searchFilter = Builders<Job>.Filter.Where(x => x.User.UserId == user.Id); var propagationResult = await dbContext.Jobs.UpdateManyAsync(searchFilter, updateDef); } //TODO: Need to do something with this propagation results man //FIXME: might have to do the same propagation for enterprise users return result; }
protected User(RegistrationModelBase model, IdentityProfile profile) : this(model) { this.Profile = profile; }