protected override bool AuthorizeCore(HttpContextBase httpContext) { bool superAdmin = false; bool isAdmin = false; bool isuser = false; IserviceAdmin spa = new serviceAdmin(); IPrincipal user = httpContext.User; bool authorize = false; string userid = user.Identity.Name; Admin _admin = spa.Get(x => x.mailAdmin == userid); if (_admin == null) { IserviceUser spu = new serviceUser(); User _user = new User(); _user = spu.Get(x => x.username == userid); if (_user != null) { isuser = true; } } else if (_admin != null) { if (_admin.isSuperAdmin) { superAdmin = true; } else { isAdmin = true; } } if (superAdmin && Roles.Contains("SuperAdmin")) { authorize = true; } if (isAdmin && Roles.Contains("SuperAdmin,Admin")) { authorize = true; } if (isuser && this.Roles.Contains("User")) { authorize = true; } return(authorize); }
public void refuseEvent(int eventid) { Event eve = this.GetById(eventid); IserviceUser spu = new serviceUser(); User creator = spu.GetById((long)eve.creatorid); IServiceMS sms = new ServiceMS(); this.Delete(eve); this.Commit(); sms.sendSMS("votre annonce :" + eve.EventTitle + " n'a pas été approuvé", creator.phone); sms.sendMail(creator.mail, "annonce réfusé", "votre annonce :" + eve.EventTitle + " n'a pas été approuvé"); }
public void acceptEvent(int eventid, int idadmin) { IserviceUser spu = new serviceUser(); Event eve = this.GetById(eventid); User creator = spu.GetById((long)eve.creatorid); eve.adminid = idadmin; this.Update(eve); this.Commit(); IServiceMS sms = new ServiceMS(); sms.sendSMS("votre annonce :" + eve.EventTitle + " a été approuver", spu.GetById((long)eve.creatorid).phone); sms.sendMail(eve.creator.mail, "annonce accepté", "votre annonce :" + eve.EventTitle + "a été approuvé vous pouvez la consulter sur notre siteweb"); }
public bool Login([FromBody] dynamic _user) { IserviceUser spu = new serviceUser(); SHA256 hash = new SHA256CryptoServiceProvider(); Byte[] originalBytes = ASCIIEncoding.Default.GetBytes(_user.password.ToString()); Byte[] encodedBytes = hash.ComputeHash(originalBytes); _user.password = BitConverter.ToString(encodedBytes); if (spu.AuthUser(_user.username.ToString(), _user.password.ToString())) { FormsAuthentication.SetAuthCookie(_user.username.ToString(), false); return(true); } else { return(false); } }