예제 #1
0
        public IActionResult SendPasswordThroughEmail([FromRoute] string email)
        {
            UserModel user = MongoUtil.GetUser(email);

            if (user != null)
            {
                var smtpClient = new SmtpClient
                {
                    Host        = "smtp.gmail.com",
                    Port        = 587,
                    EnableSsl   = true,
                    Credentials = new NetworkCredential(Environment.GetEnvironmentVariable("SmtpUserName"), Environment.GetEnvironmentVariable("SmtpPassword"))
                };

                using (var message = new MailMessage(new MailAddress(Environment.GetEnvironmentVariable("SmtpUserName"), "WebTicket"), new MailAddress(user.Email))
                {
                    Subject = "Parolă cont",
                    Body = "Salut, " + user.Surname + " " + user.Name + ",\n\n" + Environment.NewLine + Environment.NewLine + "Parola contului tău este " + user.Password + Environment.NewLine + Environment.NewLine + "Nu răspunde acestei adrese de email. Este folosită doar pentru mesaje automate!"
                })
                {
                    smtpClient.Send(message);
                }

                return(Ok("Parola a fost trimisă pe email"));
            }

            return(Ok("Adresa de email introdusă nu se regăsește în baza de date!"));
        }
예제 #2
0
        public IActionResult Signup([FromBody] UserApiModel userApiModel)
        {
            if (MongoUtil.GetUser(userApiModel.getUserModel(ModelsExtensionMethods.zeroId).Email) == null)
            {
                MongoUtil.AddUser(userApiModel.getUserModel(ModelsExtensionMethods.zeroId));
                return(Ok("Success"));
            }

            return(Conflict("Email used"));
        }
예제 #3
0
        public IActionResult GetReview([FromRoute] string eventId, [FromRoute] int pageSize, [FromRoute] int pageId)
        {
            List <ReviewModel>    reviews    = MongoUtil.GetReviews(new ObjectId(eventId), pageSize, pageId);
            List <ReviewApiModel> apiReviews = reviews.ConvertAll(new Converter <ReviewModel, ReviewApiModel>(r => {
                UserModel user      = MongoUtil.GetUser(r.UserId);
                ReviewApiModel apiR = r.getReviewApiModel(user.Name);
                return(apiR);
            }));

            return(Ok(apiReviews));
        }
예제 #4
0
        public IActionResult WhoIAm([FromHeader(Name = "Authorization")] string token)
        {
            ObjectId     userId = new ObjectId(JwtUtil.GetUserIdFromToken(token));
            UserModel    um     = MongoUtil.GetUser(userId);
            UserApiModel uam    = um.getUserApiModel();

            uam.Password = "";
            uam.Birthday = "";

            return(Ok(uam));
        }
예제 #5
0
        public IActionResult Signin([FromBody] UserApiModel userApiModel)
        {
            UserModel user = MongoUtil.GetUser(userApiModel.Email, userApiModel.Password);

            if (user != null)
            {
                string token = JwtUtil.getToken(user.Id.ToString(), user.Email, DateTime.Now.AddMinutes(30));
                return(Ok(token));
            }

            return(BadRequest("Invalid email or password!"));
        }
예제 #6
0
        public IActionResult GetReview([FromRoute] string eventId, [FromHeader(Name = "Authorization")] string userToken)
        {
            ObjectId    userId = new ObjectId(JwtUtil.GetUserIdFromToken(userToken));
            ReviewModel review = MongoUtil.GetReview(userId, new ObjectId(eventId));
            UserModel   user   = MongoUtil.GetUser(userId);

            if (review != null)
            {
                return(Ok(review.getReviewApiModel(user.Name)));
            }

            return(Ok(new ReviewModel {
                Rating = 0, Opinion = ""
            }));
        }
예제 #7
0
        public IActionResult GetMessages([FromRoute] String eventId, [FromHeader(Name = "Authorization")] string token)
        {
            ObjectId               reqUserId   = new ObjectId(JwtUtil.GetUserIdFromToken(token));
            List <MessageModel>    messages    = MongoUtil.GetMessages(new ObjectId(eventId));
            List <MessageApiModel> apiMessages = messages.ConvertAll(new Converter <MessageModel, MessageApiModel>(msg => {
                ObjectId pubUserId = msg.UserId;
                if (pubUserId == reqUserId)
                {
                    return(msg.getMessageApiModel());
                }
                msg.DateSent = msg.DateSent.AddHours(3);
                return(msg.getMessageApiModel(MongoUtil.GetUser(pubUserId).Name));
            }));

            return(Ok(apiMessages));
        }
예제 #8
0
        private async Task PingRequest(HttpContext context, WebSocket socket)
        {
            var buffer = new byte[600 * 1024];
            WebSocketReceiveResult result = await socket.ReceiveAsync(new ArraySegment <byte>(buffer), CancellationToken.None);

            string received = Encoding.Default.GetString(buffer, 0, result.Count);

            string[] splits     = received.Split(' ');
            string   eventIdStr = splits[0];
            ObjectId eventId    = new ObjectId(eventIdStr);

            ObjectId userId   = new ObjectId(JwtUtil.GetUserIdFromToken("Bearer " + splits[1]));
            string   userName = MongoUtil.GetUser(userId).Name;

            if (chatRooms.ContainsKey(eventIdStr))
            {
                chatRooms[eventIdStr].Add(socket);
            }
            else
            {
                chatRooms.AddOrUpdate(eventIdStr, new ConcurrentBag <WebSocket> {
                    socket
                }, (string x, ConcurrentBag <WebSocket> y) => { return(null); });
            }

            while (!result.CloseStatus.HasValue)
            {
                result = await socket.ReceiveAsync(new ArraySegment <byte>(buffer), CancellationToken.None);

                received = Encoding.Default.GetString(buffer, 0, result.Count);

                if (received == "")
                {
                    continue;
                }

                MessageModel msg = new MessageModel
                {
                    Message  = received,
                    UserId   = userId,
                    EventId  = eventId,
                    DateSent = DateTime.Now
                };

                MongoUtil.SaveMessage(msg);
                MessageApiModel msgApi = msg.getMessageApiModel(userName);
                string          toSend = msgApi.Message + "!#|||#!" + msgApi.DateSent + "!#|||#!" + msgApi.userName;
                Encoding.ASCII.GetBytes(toSend, 0, toSend.Length, buffer, 0);

                foreach (WebSocket ws in chatRooms[eventIdStr])
                {
                    if (ws != socket)
                    {
                        if (ws.State == WebSocketState.Open)
                        {
                            ws.SendAsync(new ArraySegment <byte>(buffer, 0, toSend.Length), result.MessageType, result.EndOfMessage, CancellationToken.None);
                        }
                    }
                }
            }

            await socket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None);
        }