public IHttpActionResult GetUserProfile([FromBody] NSALK.Models.UserProfile.SystemDataMessage incoming) { Console.WriteLine(DateTime.Now.ToString("HH:mm:ss")); NSALK.Models.UserProfile.SystemDataResponse outgoing = new Models.UserProfile.SystemDataResponse(); if (incoming != null) { NSALK.Models.UserProfile.SystemDataResponseContacts contacts = new Models.UserProfile.SystemDataResponseContacts(); int memberId = Convert.ToInt32(User.Identity.GetUserId()); using (NSAKLEntities context = new NSAKLEntities()) { #region UserProfile Info var aContact = context.members.Where(x => x.recid == memberId).FirstOrDefault(); if (aContact != null) { NSALK.Models.UserProfile.SystemDataResponseContact contact = new Models.UserProfile.SystemDataResponseContact() { Recid = aContact.recid, Firstname = aContact.firstname, Middlename = aContact.middlename, Lastname = aContact.lastname, Gender = aContact.gender, Physicaladdressunitnumber = aContact.physical_address_unit_number, Physicaladdressnumber = aContact.physical_address_number, Physicaladdressname = aContact.physical_address_name, Physicaladdresssuburb = aContact.physical_address_suburb, Physicaladdresspostcode = aContact.physical_address_postcode, Postaladdressnumber = aContact.postal_address_number, Postaladdressboxlobbylocation = aContact.postal_address_box_lobby_location, Postaladdresssuburb = aContact.postal_address_suburb, Postaladdresspostcode = aContact.postal_address_postcode, Phonehome = aContact.phone_home, Phonework = aContact.phone_work, Phonecell = aContact.phone_cell, Emailaddressdefault = aContact.email_address_default, Emailaddressalternate = aContact.email_address_alternate, Username = aContact.username, Ipaddress = aContact.ip_address, Remarks = aContact.remarks, Occupation = aContact.occupation, Otherremarks = aContact.other_remarks, Lastupdatedby = aContact.last_updated_by, Signupdate = (aContact.signup_date).ToString(), Emergencyvolunteeringstatus = Convert.ToBoolean(aContact.emergency_volunteering_status).ToString(), Mailingliststatus = Convert.ToBoolean(aContact.mailing_list_status).ToString(), Status = Convert.ToBoolean(aContact.status).ToString(), Birthdate = (aContact.birth_date).ToString(), Lastupdateddate = (aContact.last_updated_date).ToString() }; contacts.Contact.Add(contact); } outgoing.Items.Add(contacts); #endregion } } return(Ok(outgoing)); }
public IHttpActionResult StartAGroup([FromBody] NSALK.Models.UserProfile.SystemDataMessage incoming) { Console.WriteLine(DateTime.Now.ToString("HH:mm:ss")); NSALK.Models.UserProfile.SystemDataResponse outgoing = new Models.UserProfile.SystemDataResponse(); if (incoming != null) { //int memberId = Convert.ToInt32(User.Identity.GetUserId()); foreach (var cts in incoming.Contacts) { NSALK.Models.UserProfile.SystemDataResponseContacts contacts = new Models.UserProfile.SystemDataResponseContacts(); foreach (var ct in cts.Contact) { NSALK.Models.UserProfile.SystemDataResponseContact contact = new Models.UserProfile.SystemDataResponseContact(); using (NSAKLEntities context = new NSAKLEntities()) { #region Start A Group if (MvcApplication.isValidEmail(ct.Emailaddressdefault)) { string body = string.Empty; string errorMessage = "Start a Group Message Failure"; string name = ct.Firstname; string email = ct.Emailaddressdefault; string phonenumber = ct.Phonecell; string streetaddress = ct.Physicaladdressname; string suburb = ct.Physicaladdresssuburb; string city = ct.Physicaladdressunitnumber; string region = ct.Physicaladdresspostcode; using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/Content/StartaGroupEmailTemplate.html"))) { body = reader.ReadToEnd(); } body = body.Replace("{Name}", name); body = body.Replace("{Email}", email); body = body.Replace("{PhoneNumber}", phonenumber); body = body.Replace("{StreetAddress}", streetaddress); body = body.Replace("{Suburb}", suburb); body = body.Replace("{City}", city); body = body.Replace("{Region}", region); MvcApplication.SendEmail(MvcApplication.HELP_DESK_EMAIL, "Start a Group request from " + name, body, true, ref errorMessage); } else { FriendlyException.RaiseExeption("Don't have a valid email address. Please contact [email protected] ", "Error", HttpStatusCode.PreconditionFailed); } #endregion } contacts.Contact.Add(contact); } outgoing.Items.Add(contacts); } } return(Ok(outgoing)); }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { if (string.IsNullOrEmpty(context.UserName) || string.IsNullOrEmpty(context.Password)) { context.SetError("invalid_grant", "The user name or password not supplied."); return; } var extraParams = await context.Request.ReadFormAsync(); string username = extraParams["username"]; string password = extraParams["password"]; if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(password)) { context.SetError("invalid_grant", "username or password not provided."); return; } int memberId = 0; string role = "Member"; string AuthenticationType = "Authenticated"; bool isAdmin = false; string apiUrl = ""; using (NSAKLEntities asContext = new NSAKLEntities()) { string hashPassword = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(context.Password, "sha1"); try { var queryResult = ""; //var queryResult = asContext.Database.SqlQuery<List<string>>("exec spInternetUserWithTermsAccept_Validate '" + context.UserName + "','" + hashPassword + "','',''").ToList(); } catch (SqlException ex) { context.SetError("invalid_user", ex.Message); return; } catch (Exception ex) { context.SetError("invalid_user", ex.Message); return; } var internetUser = asContext.users.Where(x => x.username == context.UserName && x.password == hashPassword).FirstOrDefault(); if (internetUser == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } apiUrl = System.Configuration.ConfigurationManager.AppSettings["APIUrl"]; var memberinfo = asContext.members.Where(x => x.username == internetUser.username).FirstOrDefault(); if (internetUser == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } if (internetUser != null) { if (memberinfo != null) { memberId = memberinfo.recid; var coordinatorinfo = asContext.coordinators.Where(x => x.member_id == memberId).FirstOrDefault(); var admininfo = asContext.committees.Where(x => x.user_id == memberId).FirstOrDefault(); if (coordinatorinfo != null) { role = "Coordinator"; } if (admininfo != null) { role = "Admin"; } } if (string.IsNullOrEmpty(internetUser.username))//if interface doesnt' have IMEI and MAC, let the user log in { AuthenticationType = "UserNameBlank"; } else { AuthenticationType = "AuthenticatedValueMatch"; } } } var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName)); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, memberId.ToString())); identity.AddClaim(new Claim(ClaimTypes.Role, role.ToString())); AuthenticationProperties properties = CreateProperties(context.UserName, AuthenticationType); AuthenticationTicket ticket = new AuthenticationTicket(identity, properties); context.Validated(ticket); }
public IHttpActionResult RegisterUserProfile([FromBody] NSALK.Models.UserProfile.SystemDataMessage incoming) { Console.WriteLine(DateTime.Now.ToString("HH:mm:ss")); NSALK.Models.UserProfile.SystemDataResponse outgoing = new Models.UserProfile.SystemDataResponse(); if (incoming != null) { int memberId = Convert.ToInt32(User.Identity.GetUserId()); foreach (var cts in incoming.Contacts) { NSALK.Models.UserProfile.SystemDataResponseContacts contacts = new Models.UserProfile.SystemDataResponseContacts(); foreach (var ct in cts.Contact) { NSALK.Models.UserProfile.SystemDataResponseContact contact = new Models.UserProfile.SystemDataResponseContact(); using (NSAKLEntities context = new NSAKLEntities()) { #region Register User var usr = context.users.Where(x => x.username == ct.Username).FirstOrDefault(); if (usr != null) { FriendlyException.RaiseExeption("Login name already in use please choose another one", "Error", HttpStatusCode.PreconditionFailed); } string newPassword = "******"; if (!string.IsNullOrEmpty(ct.Password)) { newPassword = ct.Password; } else { newPassword = NSALK.MvcApplication.RandomPassword.Generate(6); } string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(newPassword, "sha1"); context.members.Add(new member { //recid = ct.recid, firstname = !string.IsNullOrEmpty(ct.Firstname) ? ct.Firstname:"", middlename = !string.IsNullOrEmpty(ct.Middlename) ? ct.Middlename:"", lastname = !string.IsNullOrEmpty(ct.Lastname) ? ct.Lastname:"", gender = !string.IsNullOrEmpty(ct.Gender) ? ct.Gender:"", physical_address_unit_number = !string.IsNullOrEmpty(ct.Physicaladdressunitnumber) ? ct.Physicaladdressunitnumber:"", physical_address_number = !string.IsNullOrEmpty(ct.Physicaladdressnumber) ? ct.Physicaladdressnumber:"", physical_address_name = !string.IsNullOrEmpty(ct.Physicaladdressname) ? ct.Physicaladdressname:"", physical_address_suburb = !string.IsNullOrEmpty(ct.Physicaladdresssuburb) ? ct.Physicaladdresssuburb:"", physical_address_postcode = !string.IsNullOrEmpty(ct.Physicaladdresspostcode) ? ct.Physicaladdresspostcode:"", postal_address_number = !string.IsNullOrEmpty(ct.Postaladdressnumber) ? ct.Postaladdressnumber:"", postal_address_box_lobby_location = !string.IsNullOrEmpty(ct.Postaladdressboxlobbylocation) ? ct.Postaladdressboxlobbylocation:"", postal_address_suburb = !string.IsNullOrEmpty(ct.Postaladdresssuburb) ? ct.Postaladdresssuburb:"", postal_address_postcode = !string.IsNullOrEmpty(ct.Postaladdresspostcode) ? ct.Postaladdresspostcode:"", phone_home = !string.IsNullOrEmpty(ct.Phonehome) ? ct.Phonehome:"", phone_work = !string.IsNullOrEmpty(ct.Phonework) ? ct.Phonework:"", phone_cell = !string.IsNullOrEmpty(ct.Phonecell) ? ct.Phonecell:"", email_address_default = !string.IsNullOrEmpty(ct.Emailaddressdefault) ? ct.Emailaddressdefault:"", email_address_alternate = !string.IsNullOrEmpty(ct.Emailaddressalternate) ? ct.Emailaddressalternate:"", username = !string.IsNullOrEmpty(ct.Username) ? ct.Username:"", ip_address = !string.IsNullOrEmpty(ct.Ipaddress) ? ct.Ipaddress:"", remarks = !string.IsNullOrEmpty(ct.Remarks) ? ct.Remarks:"", occupation = !string.IsNullOrEmpty(ct.Occupation) ? ct.Occupation:"", other_remarks = !string.IsNullOrEmpty(ct.Otherremarks) ? ct.Otherremarks:"", last_updated_by = !string.IsNullOrEmpty(ct.Lastupdatedby) ? ct.Lastupdatedby:"", signup_date = !string.IsNullOrEmpty(ct.Signupdate) ? Convert.ToDateTime(ct.Signupdate) : DateTime.Now, emergency_volunteering_status = !string.IsNullOrEmpty(ct.Emergencyvolunteeringstatus) ? Convert.ToBoolean(ct.Emergencyvolunteeringstatus): false, mailing_list_status = !string.IsNullOrEmpty(ct.Mailingliststatus) ? Convert.ToBoolean(ct.Mailingliststatus): false, status = !string.IsNullOrEmpty(ct.Status) ? Convert.ToBoolean(ct.Status):false, birth_date = !string.IsNullOrEmpty(ct.Birthdate) ? Convert.ToDateTime(ct.Birthdate) : new DateTime(1900, 01, 01), last_updated_date = DateTime.Now }); if (MvcApplication.isValidEmail(ct.Emailaddressdefault)) { string errorMessage = ""; string email = ct.Emailaddressdefault; if (MvcApplication.isValidEmail(ct.Emailaddressdefault)) { email = ct.Emailaddressdefault; } else if (MvcApplication.isValidEmail(ct.Emailaddressalternate)) { email = ct.Emailaddressalternate; } if (MvcApplication.SendEmail(email, "NSAKL Registration", "Rgistered Successfully. Your username is :" + ct.Username + Environment.NewLine + "Your new password is" + Environment.NewLine + newPassword, false, ref errorMessage)) { contact.Username = ct.Username; var user = context.users.Add(new user { username = ct.Username, password = hashedPassword }); context.SaveChanges(); } else { FriendlyException.RaiseExeption("An error occurred while sending email", "Error", HttpStatusCode.InternalServerError); } } else { FriendlyException.RaiseExeption("User don't have a valid email address. Please contact " + MvcApplication.HELP_DESK_EMAIL, "Error", HttpStatusCode.PreconditionFailed); } #endregion } contacts.Contact.Add(contact); } outgoing.Items.Add(contacts); } } return(Ok(outgoing)); }
public IHttpActionResult ForgotUserPassword([FromBody] NSALK.Models.UserProfile.SystemDataMessage incoming) { Console.WriteLine(DateTime.Now.ToString("HH:mm:ss")); NSALK.Models.UserProfile.SystemDataResponse outgoing = new Models.UserProfile.SystemDataResponse(); if (incoming != null) { int memberId = Convert.ToInt32(User.Identity.GetUserId()); foreach (var cts in incoming.Contacts) { NSALK.Models.UserProfile.SystemDataResponseContacts contacts = new Models.UserProfile.SystemDataResponseContacts(); foreach (var ct in cts.Contact) { NSALK.Models.UserProfile.SystemDataResponseContact contact = new Models.UserProfile.SystemDataResponseContact(); using (NSAKLEntities context = new NSAKLEntities()) { #region Update Password for User var user = context.members.Where(x => x.username == ct.Username).FirstOrDefault(); if (user == null) { FriendlyException.RaiseExeption("Login name does not exist", "Error", HttpStatusCode.PreconditionFailed); } if (MvcApplication.isValidEmail(user.email_address_default) || MvcApplication.isValidEmail(user.email_address_alternate)) { string newPassword = "******"; newPassword = NSALK.MvcApplication.RandomPassword.Generate(6); string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(newPassword, "sha1"); var usr = context.users.Where(x => x.username == ct.Username).FirstOrDefault(); usr.password = hashedPassword; string errorMessage = ""; string email = ct.Emailaddressdefault; if (MvcApplication.isValidEmail(user.email_address_default)) { email = user.email_address_default; } else if (MvcApplication.isValidEmail(user.email_address_alternate)) { email = user.email_address_alternate; } if (MvcApplication.SendEmail(email, "Your NSAKL password", "Your new NSAKL password is" + Environment.NewLine + newPassword, false, ref errorMessage)) { contact.Username = ct.Username; context.SaveChanges(); } else { FriendlyException.RaiseExeption("An error occurred while sending email", "Error", HttpStatusCode.InternalServerError); } } else { FriendlyException.RaiseExeption("User don't have a valid email address. Please contact " + MvcApplication.HELP_DESK_EMAIL, "Error", HttpStatusCode.PreconditionFailed); } #endregion } contacts.Contact.Add(contact); } outgoing.Items.Add(contacts); } } return(Ok(outgoing)); }
public IHttpActionResult GetDocuments([FromBody] NSALK.Models.GetDocuments.SystemDataMessage incoming) { Console.WriteLine(DateTime.Now.ToString("HH:mm:ss")); NSALK.Models.GetDocuments.SystemDataResponse outgoing = new Models.GetDocuments.SystemDataResponse(); if (incoming != null) { NSALK.Models.GetDocuments.SystemDataResponseDocuments docs = new Models.GetDocuments.SystemDataResponseDocuments(); int memberId = Convert.ToInt32(User.Identity.GetUserId()); string role = ((ClaimsIdentity)User.Identity).Claims.Where(c => c.Type == ClaimTypes.Role).Select(c => c.Value).FirstOrDefault(); using (NSAKLEntities context = new NSAKLEntities()) { #region Get Admin Documents if (role == "Admin") { var dcs = context.documents.Where(x => x.status == true).ToList(); foreach (var dc in dcs) { string dtype = context.doc_types.Where(x => x.recid == dc.doc_type_id).Select(x => x.doc_type).FirstOrDefault(); NSALK.Models.GetDocuments.SystemDataResponseDocument dct = new Models.GetDocuments.SystemDataResponseDocument() { recid = dc.recid, doc_title = dc.doc_title, doc_type = dtype, doc_author = dc.doc_author, doc_publisher = dc.doc_publisher, doc_date = Convert.ToDateTime(dc.doc_date), doc_number = dc.doc_number, doc_remarks = dc.doc_remarks, doc_path = dc.doc_path, status = Convert.ToBoolean(dc.status), uploaded_by = dc.uploaded_by, deleted_by = dc.deleted_by, date_deleted = Convert.ToDateTime(dc.date_deleted) }; docs.Document.Add(dct); } outgoing.Documents.Add(docs); } #endregion #region Get User Documents if (role == "Member") { var dcs = context.documents.Where(x => x.status == true && x.doc_type_id == 7).ToList(); foreach (var dc in dcs) { string dtype = context.doc_types.Where(x => x.recid == dc.doc_type_id).Select(x => x.doc_type).FirstOrDefault(); NSALK.Models.GetDocuments.SystemDataResponseDocument dct = new Models.GetDocuments.SystemDataResponseDocument() { recid = dc.recid, doc_title = dc.doc_title, doc_type = dtype, doc_author = dc.doc_author, doc_publisher = dc.doc_publisher, doc_date = Convert.ToDateTime(dc.doc_date), doc_number = dc.doc_number, doc_remarks = dc.doc_remarks, doc_path = dc.doc_path, status = Convert.ToBoolean(dc.status), uploaded_by = dc.uploaded_by, deleted_by = dc.deleted_by, date_deleted = Convert.ToDateTime(dc.date_deleted) }; docs.Document.Add(dct); } outgoing.Documents.Add(docs); } #endregion } } return(Ok(outgoing)); }