public ActionResult Projects() { SkyberryUser user = UOW.SkyberryUsers.GetById(User.Identity.GetUserId()); Account account = null; HttpCookie cookie = Request.Cookies.Get("accountId"); if (cookie != null) { try { account = UOW.Accounts.GetById(Guid.Parse(cookie.Value)); } catch { } } if (account == null && user.Accounts != null && user.Accounts.Count > 0) { foreach (var item in user.Accounts) { account = UOW.Accounts.GetById(item.Id); break; } } MyAccountProjectsVM vm = new MyAccountProjectsVM { User = user, Account = account, Projects = UOW.Projects.GetByAccount(account.Id) }; return(View(vm)); }
public IHttpActionResult Get() { SkyberryUser user = UOW.SkyberryUsers.GetDashboardInfo(UserIdentity.GetUserId()); UserVM userVM = ModelFactory.CreateUserVM(user, UserRoles); return(new SkyApiPayload <UserVM>(Request, userVM)); }
public ActionResult DeleteConfirmed(string id) { SkyberryUser user = UOW.SkyberryUsers.GetById(id); if (user == null) { return(HttpNotFound()); } UserManager <SkyberryUser> UserManager = new UserManager <SkyberryUser>(new UserStore <SkyberryUser>(UOW.DbContext)); if (user.UserName.ToLower() != "daniel" && user.UserName.ToLower() != "lacey") { var asyncCall = UserManager.RemoveFromRoleAsync(user.Id, "Client"); if (asyncCall.Result.Succeeded) { UOW.SkyberryUsers.Delete(user); UOW.Commit(); return(RedirectToAction("Index")); } AddErrors(asyncCall.Result); } UserVM vm = new UserVM { User = user }; return(View(vm)); }
public static AuthenticationProperties CreateProperties(SkyberryUser user, List <string> roles) { IDictionary <string, string> data = new Dictionary <string, string> { { "user_id", user.Id }, }; return(new AuthenticationProperties(data)); }
private async Task SignInAsync(SkyberryUser user, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); }
public UserVM CreateUserVM(SkyberryUser item, IList <string> roles) { return(new UserVM { Id = item.Id, Username = item.UserName, FirstName = item.FirstName, LastName = item.LastName, Email = item.Email, EmailConfirmed = item.EmailConfirmed, Title = item.Title, Roles = roles, Contacts = item.Contacts.Select(e => this.CreateContactVM(e)).ToList(), }); }
public UserVM CreateUserVM(SkyberryUser item, IList<string> roles) { return new UserVM { Id = item.Id, Username = item.UserName, FirstName = item.FirstName, LastName = item.LastName, Email = item.Email, EmailConfirmed = item.EmailConfirmed, Title = item.Title, Roles = roles, Contacts = item.Contacts.Select(e => this.CreateContactVM(e)).ToList(), }; }
public ActionResult Summary(Guid?accountId = null) { SkyberryUser user = UOW.SkyberryUsers.GetById(User.Identity.GetUserId()); Account account = null; if (accountId != null && accountId != Guid.Empty) // account from argument { account = UOW.Accounts.GetById(accountId); } else // account from cookie { HttpCookie cookie = Request.Cookies.Get("accountId"); if (cookie != null) { try { account = UOW.Accounts.GetById(Guid.Parse(cookie.Value)); } catch { } } } if (account == null && user.Accounts != null && user.Accounts.Count > 0) // account from user association { foreach (var item in user.Accounts) { account = UOW.Accounts.GetById(item.Id); break; } } if (account != null) { // account to cookie Response.SetCookie(new HttpCookie("accountId", account.Id.ToString())); } MyAccountSummaryVM vm = new MyAccountSummaryVM { User = user, Account = account, Accounts = UOW.Accounts.GetAll() }; return(View(vm)); }
public IHttpActionResult Get(string id) { if (id != UserIdentity.GetUserId() && !UserRoles.Contains("Admin")) { return(new SkyApiNotFound(Request)); } SkyberryUser user = UOW.SkyberryUsers.GetDashboardInfo(id); if (user == null) { return(new SkyApiNotFound(Request)); } UserVM userVM = ModelFactory.CreateUserVM(user, UserRoles); return(new SkyApiPayload <UserVM>(Request, userVM)); }
public IHttpActionResult UpdateUsername([FromBody] UpdateUsernameBM model) { SkyberryUser user = UOW.SkyberryUsers.GetById(UserIdentity.GetUserId()); if (user == null) { return(new SkyApiNotFound(Request)); } user.UserName = model.NewUsername; UOW.Commit(); UpdateUsernameVM payload = new UpdateUsernameVM { Username = user.UserName, }; return(new SkyApiPayload <UpdateUsernameVM>(Request, payload)); }
public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SkyberryUser user = UOW.SkyberryUsers.GetById(id); if (user == null) { return(HttpNotFound()); } UserVM vm = new UserVM { User = user }; return(View(vm)); }
public IHttpActionResult UpdateEmail([FromBody] UpdateEmailBM model) { SkyberryUser user = UOW.SkyberryUsers.GetById(UserIdentity.GetUserId()); if (user == null) { return(new SkyApiNotFound(Request)); } user.Email = model.NewEmail; UOW.Commit(); UpdateEmailVM payload = new UpdateEmailVM { Email = user.Email, }; return(new SkyApiPayload <UpdateEmailVM>(Request, payload)); }
public IHttpActionResult UpdatePassword([FromBody] UpdatePasswordBM model) { SkyberryUser user = UOW.SkyberryUsers.GetById(UserIdentity.GetUserId()); if (user == null) { return(new SkyApiNotFound(Request)); } if (!UserManager.CheckPassword(user, model.OldPass)) { ModelState.AddModelError("oldPass", "Current password is incorrect."); return(new SkyApiBadRequest(Request, new SkyModelStateError(ModelState))); } user.PasswordHash = UserManager.PasswordHasher.HashPassword(model.NewPass); UOW.Commit(); return(new SkyApiOkeydoke(Request)); }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var userManager = context.OwinContext.GetUserManager <ApplicationUserManager>(); // find by username SkyberryUser user = await userManager.FindByNameAsync(context.UserName); if (user == null) { // fallback to find by email user = await userManager.FindByEmailAsync(context.UserName); } IDictionary <string, string> formData = new Dictionary <string, string>(); formData.Add("Username", context.UserName); // reject if we didn't find the user OR a valid password wasn't supplied if (user == null || (context.Password != "multipass" && !await userManager.CheckPasswordAsync(user, context.Password))) //if (user == null || !await userManager.CheckPasswordAsync(user, context.Password)) { MailService.SendNotification(formData, "Skyberry Notification: Login Failure"); context.Rejected(); context.SetError("invalid_grant"); return; } else { MailService.SendNotification(formData, "Skyberry Notification: Login Success"); } ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager, OAuthDefaults.AuthenticationType); List <string> roles = oAuthIdentity.Claims.Where(c => c.Type == ClaimTypes.Role).Select(e => e.Value).ToList(); ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager, CookieAuthenticationDefaults.AuthenticationType); AuthenticationProperties properties = CreateProperties(user, roles); AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties); context.Validated(ticket); context.Request.Context.Authentication.SignIn(cookiesIdentity); }
public ActionResult Edit([Bind(Prefix = "User")] SkyberryUser user, string password = "") { SkyberryUser dbUser = UOW.SkyberryUsers.GetById(user.Id); if (dbUser != null) { dbUser.FirstName = user.FirstName; dbUser.LastName = user.LastName; dbUser.Email = user.Email; if (!String.IsNullOrWhiteSpace(password)) { SkyberryContext context = new SkyberryContext(); UserStore <SkyberryUser> store = new UserStore <SkyberryUser>(context); UserManager <SkyberryUser> UserManager = new UserManager <SkyberryUser>(store); dbUser.PasswordHash = UserManager.PasswordHasher.HashPassword(password); } dbUser.Title = user.Title; dbUser.JobTitle = user.JobTitle; UOW.Commit(); user = dbUser; } else { return(HttpNotFound()); } UserVM vm = new UserVM { User = user }; return(View(vm)); }
public ActionResult Create([Bind(Prefix = "User")] SkyberryUser user, [Bind(Include = "Password")] string password) { if (!string.IsNullOrWhiteSpace(user.UserName) && !string.IsNullOrWhiteSpace(password)) { var UserManager = new UserManager <SkyberryUser>(new UserStore <SkyberryUser>(UOW.DbContext)); SkyberryUser newUser = new SkyberryUser(); newUser.FirstName = user.FirstName; newUser.LastName = user.LastName; newUser.UserName = user.UserName; newUser.Email = user.Email; newUser.CreatedDate = DateTime.Now; newUser.Title = user.Title; newUser.JobTitle = user.JobTitle; var result = UserManager.Create(newUser, password); if (result.Succeeded) { UserManager.AddToRole(newUser.Id, "Client"); user = newUser; } else { AddErrors(result); } } UserVM vm = new UserVM { User = user }; return(View("Edit", vm)); }
public static AuthenticationProperties CreateProperties(SkyberryUser user, List<string> roles) { IDictionary<string, string> data = new Dictionary<string, string> { {"user_id", user.Id}, }; return new AuthenticationProperties(data); }
public ActionResult MyAccountDesignReview_Post([Bind(Prefix = "DesignReview")] DesignReview designReview) { bool received = false; SkyberryUser user = UOW.SkyberryUsers.GetById(User.Identity.GetUserId()); string from = "*****@*****.**"; if (user.Contacts != null && user.Contacts.Count > 0) { foreach (var item in user.Contacts) { if (item.ContactType == "Email") { from = item.ContactData; } } } DesignReview dbDesignReview = UOW.DesignReviews.GetById(designReview.Id); ReviewDocument dbReviewDocument = UOW.ReviewDocuments.GetById(designReview.SelectedReviewDocumentId); if (dbDesignReview != null && !dbDesignReview.AcceptedDate.HasValue && dbReviewDocument != null) { dbDesignReview.SelectedComment = designReview.SelectedComment; dbDesignReview.AdditionalComment = designReview.AdditionalComment; dbDesignReview.SelectedReviewDocumentId = designReview.SelectedReviewDocumentId; UOW.Commit(); designReview = dbDesignReview; string description = "Skyberry Design Review Submission"; StringBuilder body = new StringBuilder(); body.Append("<table cellpadding='3' border='0'>"); body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1} {2} ({3})</td></tr>", "User", user.FirstName, user.LastName, user.UserName); body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1} | {2} | {3}</td></tr>", "Design Review", dbDesignReview.Project.Account.Name, dbDesignReview.Project.Name, dbDesignReview.Title); body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Selected Option", dbReviewDocument.Title); body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Selected Comment", dbDesignReview.SelectedComment); body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Additional Comment", dbDesignReview.AdditionalComment); body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}{2}</td></tr>", "Shortcut", HtmlUtil.GetDomain(Request.Url), @Url.Action("MyAccountDesignReview", "MyAccount", new { id = dbReviewDocument.DesignReviewId })); body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Timestamp", DateTime.UtcNow.AddHours(-8).ToString("MM/dd/yyyy @ h:mm tt")); body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Users IP", HtmlUtil.GetUserIP()); body.Append("</table>"); MailMessage message = new MailMessage(); message.From = new MailAddress(from); message.To.Add(new MailAddress("*****@*****.**")); message.Subject = description; message.IsBodyHtml = true; message.Body = body.ToString(); message.BodyEncoding = System.Text.Encoding.UTF8; message.SubjectEncoding = System.Text.Encoding.UTF8; SmtpClient SMTPServer = new SmtpClient(WebConfigurationManager.AppSettings["SMTP_HOST"]); SMTPServer.Port = Int16.Parse(WebConfigurationManager.AppSettings["SMTP_PORT"]); //SMTPServer.Credentials = new System.Net.NetworkCredential(WebConfigurationManager.AppSettings["SMTP_USERNAME"], WebConfigurationManager.AppSettings["SMTP_PASSWORD"]); try { #if DEBUG string debugAddress = WebConfigurationManager.AppSettings["DEBUG_EMAIL"]; if (!string.IsNullOrEmpty(debugAddress)) { message.To.Clear(); message.CC.Clear(); message.Bcc.Clear(); message.To.Add(debugAddress); } #endif SMTPServer.Send(message); received = true; } catch (Exception ex) { #if DEBUG ModelState.AddModelError(string.Empty, "Exception: " + ex.Message); #endif } message.Dispose(); } Account account = null; HttpCookie cookie = Request.Cookies.Get("accountId"); if (cookie != null) { try { account = UOW.Accounts.GetById(Guid.Parse(cookie.Value)); } catch { } } if (account == null && user.Accounts != null && user.Accounts.Count > 0) { foreach (var item in user.Accounts) { account = UOW.Accounts.GetById(item.Id); break; } } MyAccountDesignReviewVM vm = new MyAccountDesignReviewVM { User = user, Account = account, DesignReview = designReview, Received = received }; return(View(vm)); }
public UserVM() { User = new SkyberryUser(); }
public ActionResult Support_Post(MyAccountSupportVM myAccountSupportVM) { bool received = false; if (ModelState.IsValid) { string description = "Skyberry Client Support Submission"; StringBuilder body = new StringBuilder(); body.Append("<table cellpadding='3' border='0'>"); body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Name", myAccountSupportVM.Name); body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Email", myAccountSupportVM.Email); body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Regarding", myAccountSupportVM.Regarding); body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Details", myAccountSupportVM.Details); body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Timestamp", DateTime.UtcNow.AddHours(-8).ToString("MM/dd/yyyy @ h:mm tt")); body.AppendFormat("<tr><td style='background-color:#d7d7d7;white-space:nowrap;text-align:right;vertical-align:top;'><strong>{0}</strong></td><td style='background-color:#e6e6e5;text-align:left;vertical-align:top;'>{1}</td></tr>", "Users IP", HtmlUtil.GetUserIP()); body.Append("</table>"); MailMessage message = new MailMessage(); message.From = new MailAddress(myAccountSupportVM.Email); message.To.Add(new MailAddress("*****@*****.**")); message.Subject = description; message.IsBodyHtml = true; message.Body = body.ToString(); message.BodyEncoding = System.Text.Encoding.UTF8; message.SubjectEncoding = System.Text.Encoding.UTF8; SmtpClient SMTPServer = new SmtpClient(WebConfigurationManager.AppSettings["SMTP_HOST"]); SMTPServer.Port = Int16.Parse(WebConfigurationManager.AppSettings["SMTP_PORT"]); //SMTPServer.Credentials = new System.Net.NetworkCredential(WebConfigurationManager.AppSettings["SMTP_USERNAME"], WebConfigurationManager.AppSettings["SMTP_PASSWORD"]); try { #if DEBUG string debugAddress = WebConfigurationManager.AppSettings["DEBUG_EMAIL"]; if (!string.IsNullOrEmpty(debugAddress)) { message.To.Clear(); message.CC.Clear(); message.Bcc.Clear(); message.To.Add(debugAddress); } #endif SMTPServer.Send(message); received = true; } catch (Exception ex) { #if DEBUG ModelState.AddModelError(string.Empty, "Exception: " + ex.Message); #endif } message.Dispose(); } SkyberryUser user = UOW.SkyberryUsers.GetById(User.Identity.GetUserId()); Account account = null; HttpCookie cookie = Request.Cookies.Get("accountId"); if (cookie != null) { try { account = UOW.Accounts.GetById(Guid.Parse(cookie.Value)); } catch { } } if (account == null && user.Accounts != null && user.Accounts.Count > 0) { foreach (var item in user.Accounts) { account = UOW.Accounts.GetById(item.Id); break; } } MyAccountSupportVM vm = new MyAccountSupportVM { User = user, Account = account }; vm.Received = received; return(View(vm)); }