Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Page());
            }

            // Create news
            var newMessage = new NewsMessage {
                Date  = this.dateProvider.Now,
                Text  = this.Input.Text,
                Title = this.Input.Title
            };

            this.dc.NewsMessages.Add(newMessage);
            await this.dc.SaveChangesAsync();

            // Send mailing
            var msg        = new TemplatedMailMessageDto("News");
            var recipients = await dc.Users.Where(x => x.SendNews).Select(x => new { x.Email, x.UserName, x.Language }).ToListAsync();

            foreach (var item in recipients)
            {
                msg.To.Clear();
                msg.To.Add(new MailAddressDto(item.Email, item.UserName));
                var culture = new CultureInfo(item.Language);
                await this.mailer.SendMessageAsync(msg, new { title = newMessage.Title, text = newMessage.Text }, culture, culture);
            }

            return(this.RedirectToPage("Index", null, "created"));
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync(string locale)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Page());
            }

            // Try to find user by name
            var user = await this.userManager.FindByNameAsync(this.Input.UserName).ConfigureAwait(false);

            if (user == null)
            {
                this.ModelState.AddModelError(nameof(this.Input.UserName), UI.Login_ForgotPassword_UserNotFound);
                return(this.Page());
            }

            // Get password reset token
            var token = await this.userManager.GeneratePasswordResetTokenAsync(user);

            // Get password reset URL
            var passwordResetUrl = this.Url.Page("/Login/ResetPassword",
                                                 pageHandler: null,
                                                 values: new { userId = user.Id, token = token },
                                                 protocol: this.Request.Scheme);

            // Send password reset mail
            var msg = new TemplatedMailMessageDto("PasswordReset", user.Email);

            await this.mailerService.SendMessageAsync(msg, new {
                userName = user.UserName,
                url      = passwordResetUrl
            }).ConfigureAwait(false);

            return(this.RedirectToPage("Index", null, "sent"));
        }
Esempio n. 3
0
        public async Task <IActionResult> OnPostDeleteAsync(int reservationId)
        {
            var r = await this.Init(reservationId);

            if (r == null)
            {
                return(this.NotFound());
            }

            // Send notification
            if (!string.IsNullOrEmpty(this.NotificationEmail))
            {
                var msg = new TemplatedMailMessageDto("ReservationDeleted", this.NotificationEmail);
                await this.mailer.SendMessageAsync(msg, new {
                    resourceName = this.ResourceName,
                    userName     = this.User.Identity.Name,
                    oldDateBegin = r.DateBegin,
                    oldDateEnd   = r.DateEnd,
                }, this.NotificationCulture, this.NotificationCulture);
            }

            // Delete reservation
            this.dc.Reservations.Remove(r);
            await this.dc.SaveChangesAsync();

            return(this.RedirectToPage("Index", null, "deleted"));
        }
Esempio n. 4
0
        public async Task <IActionResult> OnPostAsync(int reservationId)
        {
            var r = await this.Init(reservationId);

            if (r == null)
            {
                return(this.NotFound());
            }
            if (!this.ModelState.IsValid)
            {
                return(this.Page());
            }

            // Check reservation for conflicts
            var q = from cr in this.dc.Reservations
                    where cr.DateBegin <this.Input.DateEnd && cr.DateEnd> this.Input.DateBegin && cr.Id != r.Id
                    select new { cr.DateBegin, cr.User.UserName };

            foreach (var item in await q.ToListAsync())
            {
                this.ModelState.AddModelError(string.Empty, string.Format(UI.My_Reservations_Err_Conflict, item.UserName, item.DateBegin));
            }
            if (!this.ModelState.IsValid)
            {
                return(this.Page());
            }

            // Send notification if time changed
            if ((r.DateBegin != this.Input.DateBegin || r.DateEnd != this.Input.DateEnd) && !string.IsNullOrEmpty(this.NotificationEmail))
            {
                var msg = new TemplatedMailMessageDto("ReservationChanged", this.NotificationEmail);
                await mailer.SendMessageAsync(msg, new {
                    resourceName = this.ResourceName,
                    userName     = this.User.Identity.Name,
                    oldDateBegin = r.DateBegin,
                    oldDateEnd   = r.DateEnd,
                    dateBegin    = this.Input.DateBegin,
                    dateEnd      = this.Input.DateEnd
                }, this.NotificationCulture, this.NotificationCulture);
            }

            // Update reservation
            r.Comment   = this.Input.Comment;
            r.DateBegin = this.Input.DateBegin;
            r.DateEnd   = this.Input.DateEnd;
            r.System    = this.Input.System;

            await this.dc.SaveChangesAsync();

            return(this.RedirectToPage("Index", null, "saved"));
        }
        public async Task <IActionResult> OnPost()
        {
            // Prepare templated message
            var msg = new TemplatedMailMessageDto("Test", "*****@*****.**");

            // Send message with values
            await this.mailer.SendMessageAsync(msg, new {
                MyValue1  = 123,
                MyValue2  = "TEST",
                NullValue = (string)null
            });

            // Redirect
            return(this.RedirectToPage("Sent"));
        }
Esempio n. 6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Page());
            }

            // Create new user
            var newUser = new ApplicationUser {
                UserName    = this.Input.UserName,
                Email       = this.Input.Email,
                PhoneNumber = this.Input.PhoneNumber,
                Language    = this.Input.Language
            };
            var result = await this.userManager.CreateAsync(newUser);

            if (!this.IsIdentitySuccess(result))
            {
                return(this.Page());
            }

            // Assign roles
            if (this.Input.IsMaster)
            {
                await this.userManager.AddToRoleAsync(newUser, ApplicationRole.Master);
            }
            if (this.Input.IsAdministrator)
            {
                await this.userManager.AddToRoleAsync(newUser, ApplicationRole.Administrator);
            }

            // Get e-mail confirmation URL
            var token = await this.userManager.GenerateEmailConfirmationTokenAsync(newUser);

            var activationUrl = this.Url.Page("/Login/Activate", pageHandler: null, values: new { UserId = newUser.Id, Token = token }, protocol: this.Request.Scheme);

            // Send welcome mail
            var culture = new CultureInfo(this.Input.Language);
            var msg     = new TemplatedMailMessageDto("Activation", newUser.Email);

            await this.mailerService.SendMessageAsync(msg, new {
                userName = newUser.UserName,
                url      = activationUrl
            }, culture, culture);

            return(this.RedirectToPage("Index", null, "created"));
        }
Esempio n. 7
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Page());
            }

            // Check if the address is really changed
            var me = await this.userManager.GetUserAsync(this.User);

            if (me.Email.Equals(this.Input.Email, StringComparison.OrdinalIgnoreCase))
            {
                return(this.RedirectToPage("Index"));
            }

            // Check password
            var passwordCorrect = await this.userManager.CheckPasswordAsync(me, this.Input.CurrentPassword);

            if (!passwordCorrect)
            {
                this.ModelState.AddModelError(nameof(this.Input.CurrentPassword), UI.My_Settings_Email_InvalidPassword);
                return(this.Page());
            }

            // Get email change token
            var token = await this.userManager.GenerateChangeEmailTokenAsync(me, this.Input.Email);

            // Get email change confirmation URL
            var url = this.Url.Page("/My/Settings/EmailConfirm",
                                    pageHandler: null,
                                    values: new {
                newEmail = this.Input.Email,
                token    = token
            },
                                    protocol: this.Request.Scheme);

            // Send message
            var msg = new TemplatedMailMessageDto("EmailConfirm", this.Input.Email);

            await this.mailerService.SendMessageAsync(msg, new {
                userName = me.UserName,
                url      = url
            });

            return(this.RedirectToPage("Index", null, "changeemail"));
        }