public HttpResponseMessage GetInfo() { SalaAccess sala = new SalaAccess(); ErrorReader errorReader = new ErrorReader(); string userId = RequestContext.Principal.Identity.GetUserId(); int idSala = sala.GetIdSala(userId); if (idSala == 0) { var message = string.Format(errorReader.GetErrorMessage(9)); HttpError err = new HttpError(message); return(Request.CreateResponse(errorReader.GetError(9), err)); } else { string nomeSala = sala.GetNomeSala(idSala); bool isOnwer = sala.IsOwner(idSala, userId); InfoModel model = new InfoModel(); model.Id = idSala; model.Nome = nomeSala; model.isOwner = isOnwer; return(Request.CreateResponse(HttpStatusCode.OK, model)); } }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: resetMonth.ResetCurrentBalances(); return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); TempData["Errors"] = ErrorReader.ErrorCompiler(ModelState); return(View(model)); } }
public ActionResult Configure(ConfigureHouseViewModel model) { if (ModelState.IsValid) { var user = db.Users.Find(User.Identity.GetUserId()); var bankAccount = new BankAccount { OwnerId = user.Id, Name = model.BankName, Created = DateTime.Now, StartBal = model.StartBal, CurrentBal = model.StartBal, AccountType = model.AccountType, HouseholdId = model.HouseholdId, LowBalanceLevel = model.LowBalanceLevel }; db.Accounts.Add(bankAccount); db.SaveChanges(); var bucket = new Bucket { CurrentAmount = 0, OwnerId = user.Id, Created = DateTime.Now, Name = model.BucketName, HouseholdId = model.HouseholdId }; db.Buckets.Add(bucket); db.SaveChanges(); var bucketItem = new BucketItem { CurrentAmount = 0, BucketId = bucket.Id, Name = model.ItemName, Created = DateTime.Now, TargetAmount = model.ItemTargetAmount }; db.BucketItems.Add(bucketItem); user.Household.IsConfigured = true; db.SaveChanges(); TempData["Success"] = "Your Household is now configured."; return(RedirectToAction("Index", "Home")); } TempData["Errors"] = ErrorReader.ErrorCompiler(ModelState); return(RedirectToAction("Configure", "Households")); }
//Post: entra numa sala public HttpResponseMessage PostEntrar(NomePasswordModel model) { ErrorReader errorReader = new ErrorReader(); SalaAccess sala = new SalaAccess(); SalaUserNomePasswordModel smodel = new SalaUserNomePasswordModel(); smodel.UserId = RequestContext.Principal.Identity.GetUserId(); smodel.Nome = model.Nome; smodel.Password = model.Password; int id = sala.GetSalaId(smodel.Nome); if (id == 0) { var message = string.Format(errorReader.GetErrorMessage(1), smodel.Nome); HttpError err = new HttpError(message); return(Request.CreateResponse(errorReader.GetError(1), err)); } else { if (sala.VerificaBanUser(id, smodel.UserId)) //user esta banido da sala { var message = string.Format(errorReader.GetErrorMessage(2), smodel.Nome); HttpError err = new HttpError(message); return(Request.CreateResponse(errorReader.GetError(2), err)); } else { int return_id = sala.EntraSala(smodel); if (return_id == 0) { var message = string.Format(errorReader.GetErrorMessage(3)); HttpError err = new HttpError(message); return(Request.CreateResponse(errorReader.GetError(3), err)); } else { return(Request.CreateResponse(HttpStatusCode.OK, return_id)); } } } }
/// <summary> /// Handles the DoWork event of the errorWorker control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="DoWorkEventArgs" /> instance containing the event data.</param> void ErrorWorker_DoWork(object sender, DoWorkEventArgs e) { while (!ErrorWorker.CancellationPending && ErrorReader is not null) { // Any lines to read? int count; var buffer = new char[1024]; do { var builder = new StringBuilder(); count = ErrorReader.Read(buffer, 0, 1024); builder.Append(buffer, 0, count); ErrorWorker.ReportProgress(0, builder.ToString()); } while (count > 0); System.Threading.Thread.Sleep(200); } }
public ActionResult EditProfile(EditProfileViewModel epVM) { if (ModelState.IsValid) { var user = db.Users.Find(User.Identity.GetUserId()); user.AvatarPath = epVM.AvatarPath; user.Email = epVM.Email; user.FirstName = epVM.FirstName; user.LastName = epVM.LastName; db.SaveChanges(); return(RedirectToAction("Index", "Home")); } else { TempData["Errors"] = ErrorReader.ErrorCompiler(ModelState); return(View(epVM)); } }
public ActionResult Create([Bind(Include = "Amount,Memo,TransactionType,AccountId,BucketItemId")] Transaction transaction) { if (ModelState.IsValid) { transaction.OwnerId = User.Identity.GetUserId(); transaction.Created = DateTime.Now; db.Transactions.Add(transaction); db.SaveChanges(); transaction.UpdateBalances(); notifyMe.AccountBalanceNotifications(transaction); return(RedirectToAction("Index")); } var houseId = db.Users.Find(User.Identity.GetUserId()).HouseholdId ?? 0; ViewBag.AccountId = new SelectList(db.Accounts.Where(b => b.HouseholdId == houseId), "Id", "Name", transaction.AccountId); ViewBag.BucketItemId = new SelectList(db.BucketItems.Where(b => b.Bucket.HouseholdId == houseId), "Id", "Name", transaction.BucketItemId); TempData["Errors"] = ErrorReader.ErrorCompiler(ModelState); return(View(transaction)); }
public async Task <ActionResult> Register(AcceptInvitationViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { Email = model.Email, UserName = model.Email, LastName = model.LastName, FirstName = model.FirstName, AvatarPath = model.AvatarPath }; if (model.HouseholdId != 0) { user.HouseholdId = model.HouseholdId; } var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { if (model.HouseholdId != 0) { roleHelp.AddUserToRole(user.Id, "Member"); // fire the DidTheyJoin Notification method var invitation = db.Invitations.Find(model.Id); notifyHelp.DidTheyJoinUp(invitation); inviteHelp.MarkAsInvalid(model.Id); } await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code }, protocol: Request.Url.Scheme); await EmailHelper.ComposeEmailAsync(model, callbackUrl); return(RedirectToAction("NewlyRegistered")); } AddErrors(result); TempData["Errors"] = ErrorReader.ErrorCompiler(ModelState); } // If we got this far, something failed, redisplay form return(View(model)); }
//POST: adiciona Musica a Sala public HttpResponseMessage PostMusica(int SalaId, MusicaModel musica) { ErrorReader errorReader = new ErrorReader(); SalaAccess sala = new SalaAccess(); string userId = RequestContext.Principal.Identity.GetUserId(); if (sala.VerficaParticipante(SalaId, userId)) { sala.AdicionaMusicaSala(SalaId, musica, userId); return(Request.CreateResponse(HttpStatusCode.OK)); } else { var message = string.Format(errorReader.GetErrorMessage(4)); HttpError err = new HttpError(message); return(Request.CreateResponse(errorReader.GetError(4), err)); } }
public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); if (user == null || !await UserManager.IsEmailConfirmedAsync(user.Id)) { // Don't reveal that the user does not exist or is not confirmed return(View("ForgotPasswordConfirmation")); } string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await EmailHelper.ComposeEmailAsync(model, callbackUrl); return(RedirectToAction("ForgotPasswordConfirmation", "Account")); } // If we got this far, something failed, redisplay form TempData["Errors"] = ErrorReader.ErrorCompiler(ModelState); return(View(model)); }
public async Task <ActionResult> EditUser(UserProfileViewModel user, HttpPostedFileBase avatar) { if (ModelState.IsValid) { var myuser = db.Users.Find(user.Id); myuser.FirstName = user.FirstName; myuser.LastName = user.LastName; myuser.DisplayName = user.DisplayName; myuser.Email = user.Email; myuser.UserName = user.Email; if (avatar != null) { if (FileUploadValidator.IsWebFriendlyImage(avatar)) { var fileName = Path.GetFileName(avatar.FileName); var justFileName = Path.GetFileNameWithoutExtension(fileName); justFileName = StringUtilities.URLFriendly(justFileName); fileName = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars/"), fileName)); myuser.AvatarPath = "/Avatars/" + fileName; } } else { myuser.AvatarPath = user.AvatarPath; } db.SaveChanges(); await HttpContext.RefreshAuthentication(myuser); return(RedirectToAction("Dashboard", "Home")); } else { TempData["Errors"] = ErrorReader.ErrorCompiler(ModelState); return(RedirectToAction("EditUser")); } }
public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model) { if (!ModelState.IsValid) { TempData["Errors"] = ErrorReader.ErrorCompiler(ModelState); return(View(model)); } var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword); if (result.Succeeded) { var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); } return(RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess })); } AddErrors(result); return(View(model)); }
//POST: criar uma sala /* Coordenadas e Limites de Musicas/Horas sao opcionais */ public HttpResponseMessage PostCriar(SalaCriacaoModel model) { ErrorReader errorReader = new ErrorReader(); if (Math.Abs(model.Xcoord) > 90 || Math.Abs(model.Ycoord) > 180) { var message = string.Format(errorReader.GetErrorMessage(0)); HttpError err = new HttpError(message); return(Request.CreateResponse(errorReader.GetError(0), err)); } else { if (model.Nome.Equals("") || model.Password.Equals("")) { var message = string.Format(errorReader.GetErrorMessage(8)); HttpError err = new HttpError(message); return(Request.CreateResponse(errorReader.GetError(8), err)); } else { SalaAccess sala = new SalaAccess(); SalaCriarModel smodel = new SalaCriarModel(); smodel.UserId = RequestContext.Principal.Identity.GetUserId(); smodel.Nome = model.Nome; smodel.Password = model.Password; smodel.Xcoord = model.Xcoord; smodel.Ycoord = model.Ycoord; smodel.LimiteMusicas = model.LimiteMusicas; smodel.LimiteHorario = model.LimiteHorario; return(Request.CreateResponse(HttpStatusCode.OK, sala.CriaSala(smodel))); } } }