/// <summary> /// Sets the auth ticket. /// </summary> /// <param name="user">The user.</param> /// <param name="context">The context.</param> public static void SetAuthTicket(User user, HttpContextBase context) { var id = new System.Security.Principal.GenericIdentity(user.UserName); var tempUser = GetPrincipal(user); var serializer = new JavaScriptSerializer(); var userData = serializer.Serialize(user); var authTicket = new FormsAuthenticationTicket( 1, user.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), false, userData); var ticket = FormsAuthentication.Encrypt(authTicket); var faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticket); context.Response.Cookies.Add(faCookie); }
/// <summary> /// Checks if the user may login and sets the Session object to check later which type of user is currently logged in. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Login_Click(object sender, EventArgs e) { UserMapping userMapping = new UserMapping(); LoginMapping loginMapping = new LoginMapping(); LoginCheck.LoggedIn = false; User user = new User(); user.Email = logUserName.Text; user.Pass = logPassword.Text; try { user = loginMapping.mapFromService(service.Login2(loginMapping.mapToService(user))); if (user.MayLogin) { user = userMapping.mapFromService(service.Login2(userMapping.mapToService(user))); Session["UserObject"] = user; Session["UserObjectOwn"] = userMapping.mapFromService(service.Login2(userMapping.mapToService(user))); userOwn = (User)Session["UserObjectOwn"]; LoginCheck.LoggedIn = true; if (userOwn.UserCompany.CompanyID == 0 && userOwn.UserCv.CvID == 0) { if (userOwn.Email.Equals("*****@*****.**")) Response.Redirect("dashboardRamon.aspx"); else if (userOwn.Email.Equals("*****@*****.**")) Response.Redirect("dashboardBrian.aspx"); else if (userOwn.Email.Equals("*****@*****.**")) Response.Redirect("dashboardDennis.aspx"); else if (userOwn.Email.Equals("*****@*****.**")) Response.Redirect("dashboardJan.aspx"); } else Response.Redirect("home.aspx"); } else { errorMessage.InnerHtml = "<span>Onjuiste inloggegevens</span>"; } } catch (System.Net.WebException) { errorMessage.InnerHtml = "<span>Er kon geen verbinding gemaakt worden met de webservice<br />Probeer het later nog eens</span>"; } }
public MatchyBackend.User mapToService(User user) { CompanyMapping companyMapping = new CompanyMapping(); CvMapping cvMapping = new CvMapping(); MatchyBackend.User backEndUser = new MatchyBackend.User() { BirthDay = user.BirthDay, Email = user.Email, MayLogin = user.MayLogin, Pass = user.Pass, Type = user.Type, UserCompany = companyMapping.MapToService(user.UserCompany), UserCv = cvMapping.mapToService(user.UserCv), ProfileId = user.ProfileId }; return backEndUser; }
/// <summary> /// Checks if all the fields were Valid and sends it to the service to add the user if valid. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Reg_Click(object sender, EventArgs e) { if (IsGroupValid(regButton.ValidationGroup)) { UserMapping mapping = new UserMapping(); User userRegister = new User(); UserCv cv = null; UserCompany company = null; userRegister.Email = regMail.Text; userRegister.Pass = regPassword.Text; userRegister.BirthDay = YearTemp.Text + "-" + MonthTemp.Text + "-" + DayTemp.Text; if (cv_companyRadio.SelectedValue.Equals("Particulier")) { cv = new UserCv(); cv.Name = regFN.Text + " " + regLN.Text; cv.Age = Convert.ToInt32(cvAgeDropDown.SelectedValue); cv.City = cvCity.Text; cv.Email = userRegister.Email; cv.Province = cvProvince.Text; cv.Sex = (cvSexOption.SelectedValue).Substring(0, 1); cv.Personal = cvPersonal.Text; cv.Interests = cvInterests.Text; Education educationLevel = new Education(); educationLevel.EducationId = Convert.ToInt32(cvEducationDropDown.SelectedValue); cv.EducationLevel = educationLevel; cv.EducationHistory = cvEducation.Text; cv.Hours = cvWorkTime.SelectedValue; cv.Profession = cvProfession.Text; cv.Discipline = cvDiscipline.Text; cv.JobRequirements = cvJobRequirements.Text; cv.WorkExperience = cvWorkExperience.Text; cv.Date = DateTime.Now.ToString(); Source source = new Source(); source.Description = "Geregistreerd"; cv.Source = source; userRegister.UserCv = cv; } else if (cv_companyRadio.SelectedValue.Equals("Bedrijf")) { company = new UserCompany(); company.CompanyName = companyName.Text; company.CompanyCity = companyCity.Text; company.CompanyEmail = companyEmail.Text; company.CompanyTel = companyPhone.Text; company.CompanyDescription = companyDescription.Text; company.CompanyDate = DateTime.Now.ToString(); userRegister.UserCompany = company; } try { int returnType = service.AddUser(mapping.mapToService(userRegister)); if (returnType == 0) { errorMessage.InnerHtml = "<span>De gebruiker kon niet aangemaakt worden probeer het later nog een keer</span>"; } else if (returnType == 1) { Response.Redirect("login.aspx?registration=done"); } else { errorMessage.InnerHtml = "<span>De gebruiker bestaat al</span>"; regMail.Style["border"] = "1px solid red"; } } catch (System.Net.WebException) { errorMessage.InnerHtml = "<span>Er kon geen verbinding gemaakt worden met de webservice<br />Probeer het later nog eens</span>"; } } }
/// <summary> /// Gets the principal. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> public static CustomPrincipal GetPrincipal(User user) { return new CustomPrincipal(user.UserName) { FirstName = user.FirstName, LastName = user.LastName, UserId = user.EntityId }; }
/// <summary> /// checks which type of user is logged in (Company or Cv) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { userOwn = (User)Session["UserObjectOwn"]; checkUserType(); }
public ActionResult Register(RegisterModel registerModel) { if (ModelState.IsValid) { var userExists = _userRepository.Get(x => x.UserName.ToLower() == registerModel.UserName.ToLower()); if (userExists != null && userExists.Any()) { ViewBag.Error = "User already exists"; ViewData.Model = null; return View(); } var hashPassword = PasswordHash.CreateHash(registerModel.Password); var user = new User { FirstName = registerModel.FirstName, LastName = registerModel.LastName, UserName = registerModel.UserName, Password = hashPassword, Email = registerModel.Email }; _userRepository.Add(user); Helper.SendEmail("*****@*****.**", user.Email, "Welcome", string.Format("Please verify your email address\r\n by following this <a href={0}>link</a>", Helper.GetWelcomeEmailLink(user.UserName))); } return View(); }
/// <summary> /// The standard changeURL for profilescreen /// </summary> public virtual void changeURL() { int parseable; if (url.Contains("=")) { if(url.Contains("profile=")) profileId = Request.QueryString["profile"]; else profileId = Request.QueryString["company"]; } service = new MatchyService(); UserMapping mapping = new UserMapping(); if (Int32.TryParse(profileId, out parseable)) { try { user = mapping.mapFromService(service.GetUser(Int32.Parse(profileId))[0]); Session["UserObject"] = user; } catch { if (user.UserCv.CvID != 0) Response.Redirect("profile.aspx?profile=" + string.Format(user.ProfileId.ToString())); else Response.Redirect("company.aspx?company=" + string.Format(user.ProfileId.ToString())); } } else { if (user.UserCv.CvID != 0) Response.Redirect("profile.aspx?profile=" + string.Format(user.ProfileId.ToString())); else Response.Redirect("company.aspx?company=" + string.Format(user.ProfileId.ToString())); } }