Exemple #1
0
        public ActionResult DeletePendingConfirmed(int id)
        {
            if (Authorized(RoleType.SystemManager))
            {
                PendingUser user;
                using (PendingUsersRepository pendingUserRep = new PendingUsersRepository())
                {
                    user = pendingUserRep.GetEntity(id);

                    if (user == null)
                    {
                        return(Error(Loc.Dic.error_user_not_found));
                    }
                    if (user.CompanyId != CurrentUser.CompanyId)
                    {
                        return(Error(Loc.Dic.error_no_permission));
                    }

                    pendingUserRep.Delete(user.Id);
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Exemple #2
0
        private LogInResult ResponseIntoUser(IAuthenticationResponse response)
        {
            LogInResult logInResult = new LogInResult();
            logInResult.IsAuthenticated = true;

            var fetchResponse = response.GetExtension<FetchResponse>();
            if (fetchResponse != null)
            {
                logInResult.User = new OpenIdUser(fetchResponse, response.ClaimedIdentifier);

                using (AllUsersRepository userRep = new AllUsersRepository())
                using (PendingUsersRepository pendingUserRep = new PendingUsersRepository())
                {
                    User user = userRep.GetList().SingleOrDefault(x => x.Email == logInResult.User.Email);
                    if (user != null)
                    {
                        if (user.IsActive)
                        {
                            if (user.FirstName != logInResult.User.FirstName || user.LastName != logInResult.User.LastName)
                            {
                                user.FirstName = logInResult.User.FirstName;
                                user.LastName = logInResult.User.LastName;
                                userRep.Update(user);
                            }

                            logInResult.IsRegistered = true;
                            logInResult.User.UserId = user.Id;
                            return logInResult;
                        }
                        else
                        {
                            logInResult.IsRegistered = false;
                            logInResult.IsCanceled = true;
                            logInResult.User.UserId = user.Id;
                            return logInResult;
                        }
                    }
                    else
                    {
                        PendingUser pendingUser = pendingUserRep.GetList().SingleOrDefault(x => x.Email == logInResult.User.Email);

                        if (pendingUser != null)
                        {
                            User newUser = new User()
                            {
                                CompanyId = pendingUser.CompanyId,
                                Email = logInResult.User.Email,
                                FirstName = logInResult.User.FirstName,
                                LastName = logInResult.User.LastName,
                                CreationTime = DateTime.Now,
                                LastLogInTime = DateTime.Now,
                                Roles = pendingUser.Roles,
                                LanguageId = pendingUser.LanguageId,
                                IsActive = true
                            };

                            if (!userRep.Create(newUser))
                                return logInResult;

                            logInResult.User.UserId = newUser.Id;
                            pendingUserRep.Delete(pendingUser.Id);

                            logInResult.IsNewUser = true;
                            logInResult.IsRegistered = true;
                            return logInResult;
                        }
                        else
                        {
                            return logInResult;
                        }
                    }
                }
            }
            else
            {
                return logInResult;
            }
        }
Exemple #3
0
        public ActionResult DeletePendingConfirmed(int id)
        {
            if (Authorized(RoleType.SystemManager))
            {
                PendingUser user;
                using (PendingUsersRepository pendingUserRep = new PendingUsersRepository())
                {
                    user = pendingUserRep.GetEntity(id);

                    if (user == null)
                    {
                        return Error(Loc.Dic.error_user_not_found);
                    }
                    if (user.CompanyId != CurrentUser.CompanyId)
                    {
                        return Error(Loc.Dic.error_no_permission);
                    }

                    pendingUserRep.Delete(user.Id);
                }

                return RedirectToAction("Index");
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Exemple #4
0
        private LogInResult ResponseIntoUser(IAuthenticationResponse response)
        {
            LogInResult logInResult = new LogInResult();

            logInResult.IsAuthenticated = true;

            var fetchResponse = response.GetExtension <FetchResponse>();

            if (fetchResponse != null)
            {
                logInResult.User = new OpenIdUser(fetchResponse, response.ClaimedIdentifier);

                using (AllUsersRepository userRep = new AllUsersRepository())
                    using (PendingUsersRepository pendingUserRep = new PendingUsersRepository())
                    {
                        User user = userRep.GetList().SingleOrDefault(x => x.Email == logInResult.User.Email);
                        if (user != null)
                        {
                            if (user.IsActive)
                            {
                                if (user.FirstName != logInResult.User.FirstName || user.LastName != logInResult.User.LastName)
                                {
                                    user.FirstName = logInResult.User.FirstName;
                                    user.LastName  = logInResult.User.LastName;
                                    userRep.Update(user);
                                }

                                logInResult.IsRegistered = true;
                                logInResult.User.UserId  = user.Id;
                                return(logInResult);
                            }
                            else
                            {
                                logInResult.IsRegistered = false;
                                logInResult.IsCanceled   = true;
                                logInResult.User.UserId  = user.Id;
                                return(logInResult);
                            }
                        }
                        else
                        {
                            PendingUser pendingUser = pendingUserRep.GetList().SingleOrDefault(x => x.Email == logInResult.User.Email);

                            if (pendingUser != null)
                            {
                                User newUser = new User()
                                {
                                    CompanyId     = pendingUser.CompanyId,
                                    Email         = logInResult.User.Email,
                                    FirstName     = logInResult.User.FirstName,
                                    LastName      = logInResult.User.LastName,
                                    CreationTime  = DateTime.Now,
                                    LastLogInTime = DateTime.Now,
                                    Roles         = pendingUser.Roles,
                                    LanguageId    = pendingUser.LanguageId,
                                    IsActive      = true
                                };


                                if (!userRep.Create(newUser))
                                {
                                    return(logInResult);
                                }

                                logInResult.User.UserId = newUser.Id;
                                pendingUserRep.Delete(pendingUser.Id);

                                logInResult.IsNewUser    = true;
                                logInResult.IsRegistered = true;
                                return(logInResult);
                            }
                            else
                            {
                                return(logInResult);
                            }
                        }
                    }
            }
            else
            {
                return(logInResult);
            }
        }