Exemplo n.º 1
0
        public async Task <ActionResult> Register(AccessViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new EventorUser()
                {
                    UserName = model.RegisterModel.UserName, Name = model.RegisterModel.Name, Surname = model.RegisterModel.Surname, Email = model.RegisterModel.UserName
                };
                IdentityResult result = await UserManager.CreateAsync(user, model.RegisterModel.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRoles(user.Id, "Registred");
                    await SignInAsync(user, isPersistent : false);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View("Access", model));
        }
Exemplo n.º 2
0
        public async Task <JsonResult> AddMember(Guid EventId, string UserId, string UserRole)
        {
            MemberShip membership = new MemberShip()
            {
                EventId = EventId, UserId = UserId, UserRole = UserRole
            };

            if (_eventRepository.AddEventMember(membership))
            {
                EventorUser user = await UserManager.FindByIdAsync(UserId);

                Event @event = _eventRepository.GetEvent(EventId);

                var body = "Hello " + user.Name + " " + user.Surname + "<br />";
                body += "you have been invited to participate event called " + @event.Name + ". ";
                body += "Feel free to join it via the following link: ";
                var link = "http://eventor.cz/Event/Detail/" + @event.Name.ToSeoUrl() + "/" + @event.EventId;
                body += "<a href=\"" + link + "\">" + link + "</a><br />";
                body += "<img src=\"http://eventor.cz/Content/img/logo_120.png\"><br />";
                body += "Eventor - Be ready to your event<br />";
                body += "<a href=\"http://eventor.cz\">http://eventor.cz</a>";
                await UserManager.SendEmailAsync(UserId, "Eventor: You have been invited to event", body);

                return(Json(new { Status = true }, JsonRequestBehavior.DenyGet));
            }
            else
            {
                return(Json(new { Status = false }, JsonRequestBehavior.DenyGet));
            }
        }
Exemplo n.º 3
0
        public async Task <ActionResult> RegisterVisitor(EventDetailViewModel model)
        {
            ActionResult response = null;

            try
            {
                var currentUser = UserManager.FindByEmail(model.EventConfirmationViewModel.Email);
                if (currentUser == null) // This user name does not exists
                {
                    currentUser = new EventorUser()
                    {
                        UserName = model.EventConfirmationViewModel.Email, Email = model.EventConfirmationViewModel.Email
                    };
                    IdentityResult result = await UserManager.CreateAsync(currentUser);

                    if (result.Succeeded)
                    {
                        await UserManager.AddToRolesAsync(currentUser.Id, "Visitor");
                        await SignInAsync(currentUser, isPersistent : false);

                        response = Content("Success");
                    }
                }
            }
            catch (Exception ex)
            {
                response = Content(ex.Message);
            }
            return(response);
        }
Exemplo n.º 4
0
        private async Task SignInAsync(EventorUser user, bool isPersistent)
        {
            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
            var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);

            AuthenticationManager.SignIn(new AuthenticationProperties()
            {
                IsPersistent = isPersistent
            }, identity);
        }
Exemplo n.º 5
0
        public async Task <ActionResult> ExternalLoginConfirmation(AccessViewModel model)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                var user = new EventorUser()
                {
                    UserName = model.ExternalSignupModel.UserName, Name = model.ExternalSignupModel.Name, Surname = model.ExternalSignupModel.Surname, Email = model.ExternalSignupModel.UserName
                };

                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }

                IdentityResult result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                }

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "Registred");
                    await SignInAsync(user, isPersistent : false);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View("Access", model));
        }
Exemplo n.º 6
0
        public override Task OnDisconnected(bool stopCalled)
        {
            string userId = _repository.GetUserByConnectionId(Context.ConnectionId);

            if (userId != null)
            {
                var         connectionInfo = _repository.Users.Where(m => Guid.Equals(m.Key.Id, userId)).FirstOrDefault();
                EventorUser user           = connectionInfo.Key;
                Guid        eventId        = connectionInfo.Value;

                if (user != null)
                {
                    _repository.Remove(user);
                    Groups.Remove(Context.ConnectionId, eventId.ToString());
                    Clients.Group(eventId.ToString()).leaves(new ChatUserViewModel(user), DateTime.Now);
                }
            }

            return(base.OnDisconnected(stopCalled));
        }
Exemplo n.º 7
0
        public async Task <ActionResult> EditAccount(AccountManageViewModel model)
        {
            if (ModelState.IsValid)
            {
                var currentUser    = UserManager.FindById(User.Identity.GetUserId());
                var backupUserInfo = new EventorUser();
                backupUserInfo.Name     = currentUser.Name;
                backupUserInfo.Surname  = currentUser.Surname;
                backupUserInfo.UserName = currentUser.UserName;
                backupUserInfo.Email    = currentUser.Email;

                currentUser.Name     = model.ManageUserInfoModel.Name;
                currentUser.Surname  = model.ManageUserInfoModel.Surname;
                currentUser.UserName = model.ManageUserInfoModel.UserName;
                currentUser.Email    = model.ManageUserInfoModel.UserName;

                IdentityResult updateResult = await UserManager.UpdateAsync(currentUser);

                if (updateResult.Succeeded)
                {
                    return(RedirectToAction("Manage", new { Message = ManageMessageId.EditUserInfoSuccess }));
                }
                else
                {
                    currentUser.Name     = backupUserInfo.Name;
                    currentUser.Surname  = backupUserInfo.Surname;
                    currentUser.UserName = backupUserInfo.UserName;
                    currentUser.Email    = backupUserInfo.UserName;
                    await UserManager.UpdateAsync(currentUser);

                    return(RedirectToAction("Manage", new { Message = ManageMessageId.Error }));
                }
            }
            ViewBag.HasLocalPassword = HasPassword();
            ViewBag.ReturnUrl        = Url.Action("Manage");
            return(View("Manage", model));
        }