public async Task <ActionResult> CreateArtist(ArtistCreateView model, HttpPostedFileBase upload) { if (ModelState.IsValid) { PaskolUser user = model.UserFromArtistEditView(null); user.Status = UserStatus.Active; // Save photo if have var PhotoRes = FSservice.StorePhoto(upload, user); if (PhotoRes.Success) { user.Artist.PhotoID = PhotoRes.PhotoId; // Call userbase CreateUserAsync IdentityResult res = await CreateUserAsync(user, model.Password, new string[] { UserType.Artist.ToString() }); if (res.Succeeded) { // Create PermissionAgreement _pdfService.ArtistPermissionAgreement (DateTime.Now, user.UserName, user.Email, user.Id, WebConf.FSBaseRoute); return(RedirectToAction("Index")); } } else { ModelState.AddModelError("PictureId", PhotoRes.Message); } } return(View(model)); }
public async Task <ActionResult> EditArtist(ArtistEditView EditedArtist, HttpPostedFileBase upload) { if (ModelState.IsValid) { PaskolUser user = await UserManager .FindByIdAsync(EditedArtist.UserID); if (user != null) { var res = FSservice.StorePhoto(upload, user, user.Artist.PhotoID); if (res.Success) { // Save artist details EditedArtist.UserFromArtistEditView(user); user.Artist.PhotoID = res.PhotoId; if (await UpdateUserAsync(user, EditedArtist.Password)) { return(RedirectToAction("index")); } } else { ModelState.AddModelError("PictureId", res.Message); } } else { ModelState.AddModelError("", "משתמש לא נמצא"); } } return(View(EditedArtist)); }
public async Task <ActionResult> UserDetails(string Id) { if (string.IsNullOrEmpty(Id)) { return(RedirectToAction("Index")); } PaskolUser user = await UserManager.FindByIdAsync(Id); if (user != null) { if (user.UserType == UserType.Artist) { return(View("ArtistDetails", user.CreateArtistViewFrom())); } else if (user.UserType == UserType.Customer) { return(View("CustomerDetails", user.CreateCustomerViewFrom())); } else if (user.UserType == UserType.ArtistAgent) { return(View("ArtistAgentDetails", user.CreateCustomerViewFrom())); } } return(View("Error", new string[] { "User Not Found" })); }
public ActionResult GetBlockActive(string Id) { PaskolUser user = UserManager.Users.Single(u => u.Id == Id); ViewBag.HasUser = false; if (user != null) { ViewBag.HasUser = true; ViewBag.UserId = user.Id; ViewBag.Name = user.UserName; ViewBag.Email = user.Email; ViewBag.Roles = GetAdminRoles() .Where(ar => RoleManager.Roles.ToList() .Where(r => user.Roles.Any(ur => ur.RoleId == r.Id)) .Any(g => g.Name == ar.Key)) .Select(v => v.Value) .ToList(); ViewBag.MgrNote = user.Note; ViewBag.Status = user.Status; } // Save url to geet back to after action ends ViewBag.ReturnURL = Request.UrlReferrer; return(View()); }
internal async Task <IdentityResult> CreateUserAsync (PaskolUser user, string Password, IEnumerable <string> roles) { IdentityResult result; try { // Try to create the user result = await UserManager.CreateAsync(user, Password); if (result.Succeeded) { if (roles != null) { foreach (string role in roles) { // assign user artist to role await UserManager.AddToRoleAsync (UserManager.FindByName(user.UserName).Id, role); } } } else { AddErrorsFromResult(result); } } catch (Exception e) { throw; } return(result); }
public ResponseBase AddOrRemoveFavouriteMusic(int musicId, PaskolUser user) { var res = new ResponseBase(); try { var music = this._rep.GetByID(musicId); music.UsersFavouriteMusic = music.UsersFavouriteMusic ?? new List <PaskolUser>(); var existUser = music.UsersFavouriteMusic.FirstOrDefault(x => x.Id == user.Id); if (existUser != null) { music.UsersFavouriteMusic.Remove(existUser); } else { music.UsersFavouriteMusic.Add(user); } this._rep.Update(music); this._uow.Commit(); res.Success = true; } catch (Exception e) { res.Success = false; res.Message = e.ToString(); } return(res); }
public EntityAllResponse <Purchase> GetByArtistAgentId(string Id) { EntityAllResponse <Purchase> res = new EntityAllResponse <Purchase>(); try { // Get ArtistAgent PaskolUser artAgnt = _usersRep.GetByID(Id); if (artAgnt?.ArtistAgent != null) { res.Entities = ((IPurchaseRepository)this._rep) .GetByArtistAgntId(artAgnt.ArtistAgent.Artists.Select(u => u.User.Id).ToArray()); res.Success = true; } else { res.Message = "לא מצאנו את מנהל האמנים"; res.Success = false; } } catch (Exception e) { res.Message = e.Message; res.Success = false; } return(res); }
public EntityResponse <string> GetPurchaseHTML(int musicID, PaskolUser buyer, int cost, string reference, string permission) { var res = new EntityResponse <string>(); try { Music music = _musicRep.GetByID(musicID); res.Entity = _pdfService.GetTempPurchaseHtml( DateTime.Now, buyer.UserName, buyer.Email, music.HebrewName, music.MusicWriter, music.MusicComposer, music.MusicPerformer, permission, cost, reference, music.Exceptions); res.Success = true; } catch (Exception e) { res.Success = false; res.Message = e.ToString(); } return(res); }
public async Task <ActionResult> EditedArtist(PaskolUser ReqUser, ConfirmTypeAction confirmAction, string DeclineReason) { if (ModelState.IsValid) { PaskolUser user = UserManager.Users.SingleOrDefault(u => u.Id == ReqUser.Id); user.Artist.TempArtist.UserName = ReqUser.Artist.TempArtist.UserName; user.Artist.TempArtist.Email = ReqUser.Artist.TempArtist.Email; if (user != null) { if (await ConfirmEditedArtist(user, confirmAction, DeclineReason)) { return(RedirectToAction("Index")); } } else { ModelState.AddModelError("", "User Not Found"); } } return(View(ReqUser)); }
public async Task <ActionResult> RegisterCustomer(CustomerRegisterViewModel model) { if (ModelState.IsValid) { bool ajaxValidationResult = CaptchaControl.AjaxValidate (model.CaptchaId, model.CaptchaInput, model.InstanceId); if (ajaxValidationResult) { try { // Set customer details Customer customer = new Customer() { CompanyName = model.CompanyName }; var user = new PaskolUser { RegisteredDate = DateTime.Now, UserName = model.Name, Email = model.Email, Customer = customer, UserType = UserType.Customer, Status = UserStatus.Active }; // Create user var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { // assign user to role var roleResoult = await UserManager.AddToRoleAsync(user.Id, UserType.Customer.ToString()); // Sign in await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // email to customer EmailService.RegisterCustomer(model.Email, model.Name, model.Password); return(Json(new { suceeded = true, UserName = model.Name })); } AddErrors(result); } catch (Exception ex) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "ארעה שגיאה אנא פנה לתמיכה")); } } else { // handle not valid captcha _errors.Add(new KeyValuePair <string, string>("Captcha", "")); } } return(Json(new { suceeded = false, errors = _errors })); }
public async Task <JsonResult> updateCusomerProfile(CustomerEditView EditedCustomer, string property) { bool Succeeded = false; PaskolUser user = UserManager.FindById(User.Identity.GetUserId()); if (user != null) { // Save artist details if (property == "Name") { if (Succeeded = ModelState.IsValidField("Name")) { user.UserName = EditedCustomer.Name; } } else if (property == "Email") { if (Succeeded = ModelState.IsValidField("Email")) { user.Email = EditedCustomer.Email; } } else if (property == "Phone") { if (Succeeded = ModelState.IsValidField("Phone")) { user.PhoneNumber = EditedCustomer.Phone; } } else if (property == "CompanyName") { if (Succeeded = ModelState.IsValidField("CompanyName")) { user.Customer.CompanyName = EditedCustomer.CompanyName; } } else if (property == "Password") { Succeeded = ModelState.IsValidField("Password"); } if ((Succeeded) && await UpdateUserAsync(user, EditedCustomer.Password)) { Succeeded = true; } else { Succeeded = false; } } return(Json(new ActionResponse() { Succeeded = Succeeded, FiledErrors = DicModelState })); }
public static PaskolUser GetUser(this IPrincipal user) { PaskolUser UserToReturn = null; if (user.Identity.IsAuthenticated) { return(ServiceLocator.GetService <UsersService>().GetByID(user.Identity.GetUserId()).Entity); } return(UserToReturn); }
public static ManagersCreateView CreateManagerViewFrom(this PaskolUser user) { return(new ManagersCreateView() { UserID = user.Id, Name = user.UserName, Email = user.Email, Roles = user.Roles.Select(r => r.RoleId).ToList(), Note = user.Note }); }
public UserEditView(PaskolUser user) { UserID = user.Id; Name = user.UserName; Email = user.Email; Role = user.UserType.ToDescription(); RegisteredDate = user.RegisteredDate; Status = user.Status.ToString(); Phone = user.PhoneNumber; // סיסמה תוחלף רק את יוזן ערך בשדה. הסיסמה הקיימת לא תוצג! Note = user.Note; }
public static PaskolUser UserFromArtistAgentDetails(this ArtistAgentEditView userDetails, PaskolUser user) { PaskolUser RetUser = userDetails.UserFromUserDetails(user); if (RetUser.ArtistAgent == null) { RetUser.ArtistAgent = new ArtistAgent(); } RetUser.ArtistAgent.CompanyName = userDetails.CompanyName; RetUser.UserType = UserType.ArtistAgent; return(RetUser); }
public async Task <ActionResult> Edit(string id) { PaskolUser user = await UserManager.FindByIdAsync(id); if (user != null) { return(View(user)); } else { return(RedirectToAction("Index")); } }
public async Task <ActionResult> EditArtistAgent(string Id) { if (!string.IsNullOrEmpty(Id)) { PaskolUser user = await UserManager.FindByIdAsync(Id); if (user != null) { return(View(new ArtistAgentEditView(user))); } } return(RedirectToAction("Index")); }
public ArtistEditView(PaskolUser user) : base(user) { PictureId = user.Artist.PhotoID != null ? user.Artist.PhotoID : null; ContactManName = user.Artist.ContactManName; ContactManPhone = user.Artist.ContactManPhone; PublicPage = user.Artist.PageUrl; AgentEmail = user.Artist.AgentMail; AgentName = user.Artist.AgentName; AgentPhone = user.Artist.AgentPhone; AgentVerified = user.Artist.RelConfByArtist; Biography = user.Artist.Biography; ParticipateInAuction = user.Artist.ParticipateInAuction; PriceLevel = user.Artist.PriceLevel; }
public async Task ImpersonateUserAsync(string userName) { PaskolUser OriginalUser = null; // If user is already Impersonating then disconnect him first if (HttpContext.User.IsImpersonating()) { await RevertImpersonationAsync(); OriginalUser = this.UserManager.FindByEmail(User.GetOriginalEmail()); } else { OriginalUser = HttpContext.User.GetUser(); } PaskolUser impersonatedUser = await this.UserManager.FindByNameAsync(userName); if (impersonatedUser != null) { // If it's ok to impersonate if (ValidateImpersonating(OriginalUser, impersonatedUser)) { // Get original name and email var originalEmail = OriginalUser.Email; var originalUserName = OriginalUser.UserName; var originalType = OriginalUser.UserType; var RolesArray = RoleManager.Roles.Where(r => r.Users.Any(u => u.UserId == OriginalUser.Id)).Select(r => r.Name).ToArray(); string originalRoles = string.Join <string>(",", RolesArray); // create identity with claim to original user for impersonate user var impersonatedIdentity = await UserManager.CreateIdentityAsync(impersonatedUser, DefaultAuthenticationTypes.ApplicationCookie); // Set claims impersonatedIdentity.AddClaim(new Claim("UserImpersonation", "true")); impersonatedIdentity.AddClaim(new Claim("OriginalUsername", originalUserName)); impersonatedIdentity.AddClaim(new Claim("OriginalEmail", originalEmail)); impersonatedIdentity.AddClaim(new Claim("OriginalType", originalType.ToString())); impersonatedIdentity.AddClaim(new Claim("OriginalRoles", originalRoles)); var authenticationManager = HttpContext.GetOwinContext().Authentication; authenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, impersonatedIdentity); } } }
public static PaskolUser UserFromUserDetails(this UserEditView userDetails, PaskolUser user) { if (user == null) { user = new PaskolUser(); user.RegisteredDate = DateTime.Now; } user.UserName = userDetails.Name; user.Email = userDetails.Email; user.PhoneNumber = userDetails.Phone; user.Note = userDetails.Note; return(user); }
public static PaskolUser UserFromCustomerDetails(this CustomerEditView userDetails, PaskolUser user) { PaskolUser RetUser = userDetails.UserFromUserDetails(user); if (RetUser.Customer == null) { RetUser.Customer = new Customer(); } RetUser.Customer.CompanyName = userDetails.CompanyName; RetUser.UserType = UserType.Customer; return(RetUser); }
public async Task <ActionResult> EditArtist(string Id) { if (!string.IsNullOrEmpty(Id)) { PaskolUser user = await this.UserManager.Users .SingleOrDefaultAsync(c => c.Id == Id); if (user != null) { return(View(new ArtistEditView(user))); } } return(RedirectToAction("Index")); }
private bool ValidateImpersonating(PaskolUser OriginalUser, PaskolUser ImpersonateUser) { try { return(((OriginalUser.UserType == UserType.Admin || User.GetOriginalType() == UserType.Admin) && (ImpersonateUser.UserType == UserType.Artist || ImpersonateUser.UserType == UserType.Customer)) || ((OriginalUser.UserType == UserType.ArtistAgent || User.GetOriginalType() == UserType.ArtistAgent) && OriginalUser.ArtistAgent.Artists.Any(a => a.User.Id == ImpersonateUser.Id && a.RelConfByArtistAgent))); } catch (Exception ex) { return(false); } }
public async Task <ActionResult> NewArtist(string Id) { if (!string.IsNullOrEmpty(Id)) { PaskolUser user = await UserManager.FindByIdAsync(Id); if (user != null) { // Save url to geet back to after action ends ViewBag.ReturnURL = Request.UrlReferrer; return(View(new ArtistEditView(user))); } } return(RedirectToAction("Index")); }
public async Task <ActionResult> ArtistRegister(ArtistResiterViewModel model) { if (ModelState.IsValid) { try { Artist artist = new Artist() { ContactManName = "some name" }; var user = new PaskolUser { UserName = model.Name, Email = model.Email, Artist = artist }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { if (!RoleManager.RoleExists("Artist")) { RoleManager.Create(new PaskolRole("Artist")); } // assign user artist to role var roleResoult = await UserManager.AddToRoleAsync(UserManager.FindByName(model.Name).Id, "someRole"); // await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } catch (Exception e) { throw; } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> EditedArtist(string Id) { if (!string.IsNullOrEmpty(Id)) { PaskolUser user = await UserManager.Users.Include("Artist.TempArtist") .SingleOrDefaultAsync(u => u.Id == Id); if (user != null) { // Save url to geet back to after action ends ViewBag.ReturnURL = Request.UrlReferrer; return(View(user)); } } return(RedirectToAction("Index")); }
internal async Task <bool> UpdateUserAsync(PaskolUser user, string Password) { bool FinalRes = false; IdentityResult validEmail = await UserManager.UserValidator.ValidateAsync(user); if (!validEmail.Succeeded) { AddErrorsFromResult(validEmail, "Email"); } IdentityResult validPass = null; if (!string.IsNullOrEmpty(Password)) { validPass = await UserManager .PasswordValidator.ValidateAsync(Password); if (validPass.Succeeded) { user.PasswordHash = UserManager.PasswordHasher.HashPassword(Password); } else { AddErrorsFromResult(validPass, "Password"); } } if ((validEmail.Succeeded && validPass == null) || (validEmail.Succeeded && Password != string.Empty && validPass.Succeeded)) { IdentityResult result = await UserManager.UpdateAsync(user); if (result.Succeeded) { FinalRes = true; } else { AddErrorsFromResult(result); } } return(FinalRes); }
public async Task <ActionResult> CreateCustomer(CustomerEditView model) { if (ModelState.IsValid) { PaskolUser user = model.UserFromCustomerDetails(null); user.Status = UserStatus.Active; IdentityResult res = await CreateUserAsync(user, model.Password, new string[] { UserType.Customer.ToString() }); if (res.Succeeded) { return(RedirectToAction("Index")); } } return(View()); }
public async Task <bool> ConfirmEditedArtist(PaskolUser User, ConfirmTypeAction Action, string DeclineReason) { bool ActionSuccess = false; switch (Action) { case ConfirmTypeAction.Ok: User.Status = UserStatus.Active; if (!string.IsNullOrEmpty(User.Artist.TempArtist.Email)) { User.Email = User.Artist.TempArtist.Email; } if (!string.IsNullOrEmpty(User.Artist.TempArtist.UserName)) { User.UserName = User.Artist.TempArtist.UserName; } break; case ConfirmTypeAction.Decline: User.Status = UserStatus.WaitingNewArtist; MAILService.DeclineNewUpdateArtist(User.Email, DeclineReason); break; case ConfirmTypeAction.Block: // should delete from temp??? User.Status = UserStatus.Blocked; break; } if (await UpdateUserAsync(User, null)) { var res = service.Delete(User.Id); if (res.Success) { ActionSuccess = true; } ModelState.AddModelError("", res.Message); } return(ActionSuccess); }
public async Task <ActionResult> EditCustomer(CustomerDetailsView EditedCustomer) { PaskolUser user = await UserManager.FindByIdAsync(EditedCustomer.UserID); if (user != null) { // Save artist details EditedCustomer.UpdatePaskolUserFrom(user); IdentityResult validPass = null; if (EditedCustomer.Password != null) { validPass = await UserManager.PasswordValidator.ValidateAsync(EditedCustomer.Password); if (validPass.Succeeded) { user.PasswordHash = UserManager.PasswordHasher.HashPassword(EditedCustomer.Password); IdentityResult result = await UserManager.UpdateAsync(user); if (result.Succeeded) { return(RedirectToAction("Index")); } else { AddErrorsFromResult(result); } } else { AddErrorsFromResult(validPass); } } } else { ModelState.AddModelError("", "User Not Found"); } return(View("UserDetails", user)); }