Exemple #1
0
        private void SendEmailExecute()
        {
            Random rand = new Random();

            code = rand.Next(1000, 9999).ToString();
            Customer customer = CustomerRepository.FindByPredicate(cust => cust.Email == Email).FirstOrDefault();

            if (customer != null)
            {
                PostEmail.SendEmail(Email, $"Ваш код: {code}, Логин: {customer.Login}");
            }
            else
            {
                MessageBox.Show("На данную почту не зарегистрированы пользователи");
            }
        }
Exemple #2
0
        private void ExecuteAccept(object sender)
        {
            Order order = (sender as Button).DataContext as Order;

            try
            {
                foreach (Ordered ordered in order.Ordered)
                {
                    if (ordered.Product.Amount - ordered.Amount >= 0)
                    {
                        ordered.Product.Amount -= ordered.Amount;
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("Количество товара");
                    }
                }
                OrderRepository.SaveChanges();
                order.State = State.Approved;
                OrderRepository.SaveChanges();
            }
            catch (Exception e)
            {
                MessageBox.Show($"Невозможно принять заказ: {e.Message}");
                return;
            }

            StringBuilder message = new StringBuilder($"Заказ N{order.Id} подтвержден");

            message.Append("<table border=\"1\"><tr><td>Название</td><td>Количество</td><td>Цена за шт</td></tr>");

            decimal total = 0;

            foreach (var ordered in order.Ordered)
            {
                total += ordered.Product.Price * ordered.Amount;
                message.Append($"<tr><td>{ordered.Product.Name}</td><td>{ordered.Amount}</td><td>{ordered.Product.Price:0.00}</td></tr>");
            }
            message.Append($"</table><br><b>К оплате:{total:0.00}</b>");

            PostEmail.SendEmail(order.Customer.Email, message.ToString());
            UpdateLists();
        }
Exemple #3
0
        public static void ListenCommunication()
        {
            var factory = new ConnectionFactory()
            {
                Uri = new Uri(_urlConection)
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    var exchargeName = "SenderNotification";
                    channel.ExchangeDeclare(exchange: exchargeName, type: ExchangeType.Fanout);

                    var queueName = channel.QueueDeclare().QueueName;
                    channel.QueueBind(queue: queueName,
                                      exchange: exchargeName,
                                      routingKey: "");

                    var consumer = new EventingBasicConsumer(channel);
                    consumer.Received += (model, ea) =>
                    {
                        try
                        {
                            var body    = ea.Body.ToArray();
                            var message = Encoding.UTF8.GetString(body);
                            var entity  = JsonConvert.DeserializeObject <SenderEntity>(message);
                            PostEmail.SendEmail(entity);
                            channel.BasicAck(ea.DeliveryTag, false);
                        }
                        catch (System.Exception)
                        {
                            channel.BasicNack(ea.DeliveryTag, false, true);
                        }
                    };
                    channel.BasicConsume(queue: queueName,
                                         autoAck: false,
                                         consumer: consumer);
                    Console.ReadLine();
                }
        }
Exemple #4
0
        public HttpResponseMessage RecoveryPassword([FromBody] UserModel user)
        {
            try
            {
                using (var db = new OnlineMusicEntities())
                {
                    var userData = (from u in db.Users
                                    where u.Username.ToLower() == user.Username.ToLower() && u.Email.ToLower() == user.Email.ToLower()
                                    select u).FirstOrDefault();

                    if (userData == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Email sử dụng không trùng khớp với tài khoản"));
                    }

                    MemoryCacher cache = new MemoryCacher();
                    if (cache.Get(userData.Username) == null)
                    {
                        // Recovery password for user
                        var    rand        = new Random();
                        byte[] randomBytes = Encoding.UTF8.GetBytes(rand.Next(100000, 999999).ToString());
                        string newPassword = Convert.ToBase64String(randomBytes);

                        string subject  = "Recovery password in Musikai";
                        string htmlBody = String.Format(@"<html><body>
                            <h1>Hello, {0}</h1>
                            <p style=""font-size: 30px"">Your temporary password is <em>{1}</em></p>
                            <p style=""font-size: 27px"">The password is temporary and will expire within 3 days</p>
                            <p style=""font-size: 25px""><strong>We recommend you change your own password after you login</strong></p>
                                                    </body></html>", userData.Username, newPassword);
                        if (PostEmail.Send(userData.Email, subject, htmlBody))
                        {
                            newPassword = Convert.ToBase64String(Encoding.UTF8.GetBytes(newPassword));
                            string encryptedPassword = HashingPassword.HashPassword(newPassword);
                            cache.Add(userData.Username, encryptedPassword, DateTimeOffset.Now.AddDays(3));

                            Notification notification = new Notification()
                            {
                                Title     = "Phục hồi mật khẩu",
                                Message   = "Mật khẩu tạm thời của bạn đã được gửi tới email. Sau khi đăng nhập khuyên cáo bạn nên thay đổi mật khẩu của mình",
                                UserId    = userData.Id,
                                IsMark    = false,
                                CreatedAt = DateTime.Now,
                                Action    = NotificationAction.RECOVERY_PASSWORD
                            };
                            db.Notifications.Add(notification);

                            db.SaveChanges();
                            return(Request.CreateResponse(HttpStatusCode.OK, "Mật khẩu khôi phục đã được gửi tới email " + userData.Email));
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.InternalServerError));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, "Mật khẩu phục hồi đã gửi tới email"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.StackTrace));
            }
        }