protected void Session_Start(Object sender, EventArgs e) { if (HttpContext.Current.User != null) { // see if this user is authenticated, any authenticated cookie (ticket) exists for this user if (HttpContext.Current.User.Identity.IsAuthenticated) { // see if the authentication is done using FormsAuthentication if (HttpContext.Current.User.Identity is FormsIdentity) { Session["CurrentUser"] = AuthProvider.LoginWithDomain(HttpContext.Current.User.Identity.Name); Session["CurrentUserId"] = (new UsersDal()).GetUserGUIDByLogin(AuthProvider.LoginWithDomain(HttpContext.Current.User.Identity.Name)); var dal = new UsersDal(); dal.UsersStatisticsUpdateLoginCount(AuthProvider.UserKey(Session)); } } } // LoadBackGround var random = new Random(); int randomNumber = random.Next(1, 8); Session["bg_image_url"] = string.Format("Images/layout/theme/bg{0}.jpg", randomNumber); }
protected void Unnamed1_Authenticate(object sender, AuthenticateEventArgs e) { bool valid = false; using (var context = new PrincipalContext(ContextType.Domain)) { var login = sender as System.Web.UI.WebControls.Login; if (login != null) { valid = context.ValidateCredentials(login.UserName, login.Password); if (valid) { var dal = new UsersDal(); var loginWithDomain = AuthProvider.LoginWithDomain(login.UserName); if (!dal.IsUserExists(AuthProvider.LoginWithDomain(login.UserName))) { Session["CurrentUserId"] = dal.RegisterNewUser(loginWithDomain, AuthProvider.GetUserFullNameByDomainIdentity(login.UserName)); Login1.DestinationPageUrl = "Profile.aspx"; //e.Authenticated = false; //return; } else { Session["CurrentUserId"] = (new UsersDal()).GetUserGUIDByLogin(loginWithDomain); } Session["CurrentUser"] = loginWithDomain; dal.UsersStatisticsUpdateLoginCount(AuthProvider.UserKey(Session)); } } } e.Authenticated = valid; }
public static void AssignDefaultRoleForUser(string userName) { var dal = new UsersDal(); if (!dal.IsUserExists(userName)) { //add new user to table //and assign User Role to him dal.InsertUserWithDefaultRole(userName); } }
protected void Page_Load(object sender, EventArgs e) { var dal = new UsersDal(); GridViewMLeaderBoard.DataSource = dal.GetUserLeaderBordList(); GridViewMLeaderBoard.DataBind(); pbStageProgress.Value = (new StagesDal()).GetCurrentStageProgress(); var devLeader = dal.GetStageLeader("Software Engineering"); var qcLeader = dal.GetStageLeader("Quality Control"); var twLeader = dal.GetStageLeader("Technical Communication"); if (devLeader != null && devLeader.Tables.Count > 0 && devLeader.Tables[0].Rows.Count > 0) { LeaderPreviewDev.Title = "Software Engineering"; LeaderPreviewDev.UserName = devLeader.Tables[0].Rows[0].ItemArray[6].ToString(); LeaderPreviewDev.UserFullName = devLeader.Tables[0].Rows[0].ItemArray[0].ToString(); LeaderPreviewDev.ImageUrl = devLeader.Tables[0].Rows[0].ItemArray[1].ToString(); LeaderPreviewDev.EmblemUrl = devLeader.Tables[0].Rows[0].ItemArray[2].ToString(); LeaderPreviewDev.CountMissionsDoneByUser = Convert.ToInt32(devLeader.Tables[0].Rows[0].ItemArray[3]); LeaderPreviewDev.MissionsOnStage = Convert.ToInt32(devLeader.Tables[0].Rows[0].ItemArray[4]); LeaderPreviewDev.PercentageOfWork = Convert.ToDecimal(devLeader.Tables[0].Rows[0].ItemArray[5]); LeaderPreviewDev.UserName = devLeader.Tables[0].Rows[0].ItemArray[6].ToString(); } if (qcLeader != null && qcLeader.Tables.Count > 0 && qcLeader.Tables[0].Rows.Count > 0) { LeaderPreviewQC.Title = "Quality Control"; LeaderPreviewQC.UserName = qcLeader.Tables[0].Rows[0].ItemArray[6].ToString(); LeaderPreviewQC.UserFullName = qcLeader.Tables[0].Rows[0].ItemArray[0].ToString(); LeaderPreviewQC.ImageUrl = qcLeader.Tables[0].Rows[0].ItemArray[1].ToString(); LeaderPreviewQC.EmblemUrl = qcLeader.Tables[0].Rows[0].ItemArray[2].ToString(); LeaderPreviewQC.CountMissionsDoneByUser = Convert.ToInt32(qcLeader.Tables[0].Rows[0].ItemArray[3]); LeaderPreviewQC.MissionsOnStage = Convert.ToInt32(qcLeader.Tables[0].Rows[0].ItemArray[4]); LeaderPreviewQC.PercentageOfWork = Convert.ToDecimal(qcLeader.Tables[0].Rows[0].ItemArray[5]); } if (twLeader != null && twLeader.Tables.Count > 0 && twLeader.Tables[0].Rows.Count > 0) { LeaderPreviewTW.Title = "Technical communication"; LeaderPreviewTW.UserName = twLeader.Tables[0].Rows[0].ItemArray[6].ToString(); LeaderPreviewTW.UserFullName = twLeader.Tables[0].Rows[0].ItemArray[0].ToString(); LeaderPreviewTW.ImageUrl = twLeader.Tables[0].Rows[0].ItemArray[1].ToString(); LeaderPreviewTW.EmblemUrl = twLeader.Tables[0].Rows[0].ItemArray[2].ToString(); LeaderPreviewTW.CountMissionsDoneByUser = Convert.ToInt32(twLeader.Tables[0].Rows[0].ItemArray[3]); LeaderPreviewTW.MissionsOnStage = Convert.ToInt32(twLeader.Tables[0].Rows[0].ItemArray[4]); LeaderPreviewTW.PercentageOfWork = Convert.ToDecimal(twLeader.Tables[0].Rows[0].ItemArray[5]); } }
protected void BtnAdd_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(TbUserLogin.Text)) { var dal = new UsersDal(); if (!dal.IsUserExists(TbUserLogin.Text)) { dal.RegisterNewUser(AuthProvider.LoginWithDomain(TbUserLogin.Text), AuthProvider.GetUserFullNameByDomainIdentity(TbUserLogin.Text)); TbUserLogin.Text = string.Empty; lblUserName.Text = string.Empty; LblDepartment.Text = string.Empty; LblEmail.Text = string.Empty; LblOffice.Text = string.Empty; ReloadData(); } } }
private string SavePostedFile(UploadedFile uploadedFile) { if (!uploadedFile.IsValid) return "File is not valid"; var usersDal = new UsersDal(); var fileExtension = GetExtension(uploadedFile.FileName); var guid = Guid.NewGuid(); var dirPath = MapPath(UploadDirectory + AuthProvider.GetNameWithoutDomain(Page.User.Identity.Name)); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } string fileName = Path.Combine(dirPath, guid.ToString() + fileExtension); uploadedFile.SaveAs(fileName, true); //create a Bitmap from the file and add it to the list var bitmap = new Bitmap(fileName); if (bitmap.Height > 128 || bitmap.Width > 128) { return "File size is invalid. Image can not be bigger than 128x128 pixels."; } usersDal.RegisterNewUserAvatar(guid.ToString() + fileExtension, AuthProvider.UserKey(Session)); //clear old Data var emblemKey = usersDal.GetUserEmblem(AuthProvider.UserKey(Session)); var avatarKey = usersDal.GetUserAvatar(AuthProvider.UserKey(Session)); var filePath1 = dirPath + "\\" + (avatarKey ?? string.Empty); var filePath2 = dirPath + "\\" + (emblemKey ?? string.Empty); foreach (var f in Directory.GetFiles(dirPath)) { try { if ((f != filePath1) && (f != filePath2)) File.Delete(f); } catch (Exception) { } } return string.Empty; }
protected void UsersGrid_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) { var dal = new UsersDal(); if (!dal.UserHasActiveMissions((Guid)e.Values["UserId"])) { dal.DeleteUser((Guid) e.Values["UserId"]); } else { //todo create message } }
public void DeleteAllTempFiles() { var usersDal = new UsersDal(); var emblemKey = usersDal.GetUserEmblem(AuthProvider.UserKey(Session)); var avatarKey = usersDal.GetUserAvatar(AuthProvider.UserKey(Session)); var dirPath = MapPath(BadgesLogoDirectory); var filePath1 = dirPath + "\\" + (avatarKey ?? string.Empty); var filePath2 = dirPath + "\\" + (emblemKey ?? string.Empty); foreach (var f in Directory.GetFiles(dirPath)) { try { if ((f != filePath1) && (f != filePath2)) File.Delete(f); } catch (Exception) { } } }