//REMOTE Validation public JsonResult CheckEmailIsUsed(string emailAddress) { //Get Current Member var member = Member.GetCurrentMember(); //Sometimes inconsistent results with GetCurrent Member, unsure why?! if (member != null) { //if the email is the same as the one stored then it's OK if (member.Email == emailAddress) { //Email is the same as one currently stored on the member - so email ok to use & rule valid (return true, back to validator) return(Json(true, JsonRequestBehavior.AllowGet)); } //Try and get member by email typed in var checkEmail = Member.GetMemberFromEmail(emailAddress); if (checkEmail != null) { return(Json(String.Format(DictionaryHelper.GetDictItem("EmailAddressInUse", "The email address '{0}' is already in use."), emailAddress), JsonRequestBehavior.AllowGet)); } return(Json(true, JsonRequestBehavior.AllowGet)); } //Unable to get current member to check (just an OK for client side validation) //and let action in controller validate return(Json(true, JsonRequestBehavior.AllowGet)); }
public JsonResult CheckProfileURLAvailable(string profileURL) { //Get Current Member var member = Member.GetCurrentMember(); //Get all members where profileURL property = value from Model Member checkProfileURL = Member.GetAllAsList().FirstOrDefault(x => x.getProperty("profileURL").Value.ToString() == profileURL); //Sometimes inconsistent results with GetCurrent Member, unsure why?! if (member != null) { if (member.getProperty("profileURL").Value.ToString() == profileURL) { //profile URL is the same as one currently stored - so it's ok to use & rule valid (return true, back to validator) return(Json(true, JsonRequestBehavior.AllowGet)); } //Check not null if not null then its got one in the system already if (checkProfileURL != null) { return(Json(String.Format(DictionaryHelper.GetDictItem("ProfileURLInUse", "The profile URL '{0}' is already in use."), profileURL), JsonRequestBehavior.AllowGet)); } // no profile has this url so its all good in the hood return(Json(true, JsonRequestBehavior.AllowGet)); } //No Current Member - most likely from register form then //Check not null if not null then its got one in the system already if (checkProfileURL != null) { return(Json(String.Format(DictionaryHelper.GetDictItem("ProfileURLInUse", "The profile URL '{0}' is already in use."), profileURL), JsonRequestBehavior.AllowGet)); } //Unable to get current member to check (just an OK for client side validation) //and let action in controller validate return(Json(true, JsonRequestBehavior.AllowGet)); }
public override ActionResult Index(RenderModel model) { //Get profileURLtoCheck string profileURLtoCheck = Request.RequestContext.RouteData.Values["profileURLtoCheck"].ToString(); //Create a view model ViewProfileViewModel profile = new ViewProfileViewModel(); //Check we have a value in the URL if (!String.IsNullOrEmpty(profileURLtoCheck)) { //Try and find member with the QueryString value ?profileURLtoCheck=warrenbuckley Member findMember = Member.GetAllAsList().FirstOrDefault(x => x.getProperty("profileURL").Value.ToString() == profileURLtoCheck); //Check if we found member if (findMember != null) { //Increment profile view counter by one int noOfProfileViews = 0; int.TryParse(findMember.getProperty("numberOfProfileViews").Value.ToString(), out noOfProfileViews); //Increment counter by one findMember.getProperty("numberOfProfileViews").Value = noOfProfileViews + 1; //Save it down to the member findMember.Save(); int noOfLogins = 0; int.TryParse(findMember.getProperty("numberOfLogins").Value.ToString(), out noOfLogins); //Got the member lets bind the data to the view model profile.Name = findMember.Text; profile.MemberID = findMember.Id; profile.EmailAddress = findMember.Email; profile.Description = findMember.getProperty("description").Value.ToString(); profile.LinkedIn = findMember.getProperty("linkedIn").Value.ToString(); profile.Skype = findMember.getProperty("skype").Value.ToString(); profile.Twitter = findMember.getProperty("twitter").Value.ToString(); profile.NumberOfLogins = noOfLogins; profile.LastLoginDate = DateTime.ParseExact(findMember.getProperty("lastLoggedIn").Value.ToString(), "dd/MM/yyyy @ HH:mm:ss", CultureInfo.InvariantCulture); profile.NumberOfProfileViews = noOfProfileViews; } else { //Couldn't find the member return a 404 return(new HttpNotFoundResult(DictionaryHelper.GetDictItem("MemberProfileDoesNotExist", "The member profile does not exist"))); } } else { //Couldn't find the member return a 404 return(new HttpNotFoundResult(DictionaryHelper.GetDictItem("NoProfileURLParameter", "No profile URL parameter was provided"))); } //Return template with our profile model return(CurrentTemplate(profile)); }
public ActionResult HandleLogin(LoginViewModel model) { if (!ModelState.IsValid) { return(CurrentUmbracoPage()); } //Member already logged in - redirect to home if (Member.IsLoggedOn()) { return(Redirect("/")); } //Lets TRY to log the user in try { //Try and login the user... if (Membership.ValidateUser(model.EmailAddress, model.Password)) { //Valid credentials //Get the member from their email address var checkMember = Member.GetMemberFromEmail(model.EmailAddress); //Check the member exists if (checkMember != null) { //Let's check they have verified their email address if (Convert.ToBoolean(checkMember.getProperty("hasVerifiedEmail").Value)) { //Update number of logins counter int noLogins = 0; if (int.TryParse(checkMember.getProperty("numberOfLogins").Value.ToString(), out noLogins)) { //Managed to parse it to a number //Don't need to do anything as we have default value of 0 } //Update the counter checkMember.getProperty("numberOfLogins").Value = noLogins + 1; //Update label with last login date to now checkMember.getProperty("lastLoggedIn").Value = DateTime.Now.ToString("dd/MM/yyyy @ HH:mm:ss"); //Update label with last logged in IP address & Host Name string hostName = Dns.GetHostName(); string clientIPAddress = Dns.GetHostAddresses(hostName).Where(x => x.AddressFamily == AddressFamily.InterNetwork).FirstOrDefault().ToString(); checkMember.getProperty("hostNameOfLastLogin").Value = hostName; checkMember.getProperty("IPofLastLogin").Value = clientIPAddress; //Save the details checkMember.Save(); //If they have verified then lets log them in //Set Auth cookie FormsAuthentication.SetAuthCookie(model.EmailAddress, true); //Once logged in - redirect them back to the return URL return(new RedirectResult(model.ReturnUrl)); } else { //User has not verified their email yet ModelState.AddModelError("LoginForm.", DictionaryHelper.GetDictItem("EmailAccountNotVerified", "Email account has not been verified. A verification email has been resent to you.")); //Get the verify guid on the member (so we can resend out verification email) var verifyGUID = checkMember.getProperty("emailVerifyGUID").Value.ToString(); //Get Email Settings from Login Node (current node) var emailFrom = CurrentPage.GetPropertyValue("emailFrom", "*****@*****.**").ToString(); var emailSubject = CurrentPage.GetPropertyValue("emailSubject", "CWS - Verify Email").ToString(); //Send out verification email, with GUID in it EmailHelper.SendVerifyEmail(checkMember.Email, emailFrom, emailSubject, verifyGUID); return(CurrentUmbracoPage()); } } } else { ModelState.AddModelError("LoginForm.", "Invalid details"); return(CurrentUmbracoPage()); } } catch (Exception ex) { ModelState.AddModelError("LoginForm.", "Error: " + ex.ToString()); return(CurrentUmbracoPage()); } //In theory should never hit this, but you never know... return(RedirectToCurrentUmbracoPage()); }