示例#1
0
        /// <summary>
        /// Save credentials to phone
        /// </summary>
        private void SaveCredentials()
        {
            ICredentials credentials = new Credentials();

            if (RememberMe)
            {
                credentials.Email      = Email;
                credentials.Password   = Password;
                credentials.RememberMe = RememberMe;
            }
            CredentialsRepository.Save(credentials);
        }
示例#2
0
        public IDtoOutObjects CreateUser(DtoInUser dtoInUser)
        {
            string  deviceName = dtoInUser.DeviceName;
            User    user       = new User();
            var     configIn   = new MapperConfiguration(cfg => { cfg.CreateMap <DtoInUser, User>(); });
            IMapper mapperIn   = configIn.CreateMapper();

            mapperIn.Map(dtoInUser, user);
            user.BornDate = new DateTime(dtoInUser.Year, dtoInUser.Month, dtoInUser.Day);
            try
            {
                if (!UserExists(user))
                {
                    Credential c = new Credential(user.Email, Guid.NewGuid().ToString(), user);

                    Credential credential = credentialsRepository.Add(c);
                    credentialsRepository.Save();
                    User u = _usersRepostiory.FindBy(x => x.Id == user.Id && x.IsDeleted == false).FirstOrDefault();
                    #region createMapperUser
                    var     config = new MapperConfiguration(cfg => { cfg.CreateMap <User, DtoOutUser>(); });
                    IMapper mapper = config.CreateMapper();
                    #endregion
                    DtoOutUser dtoOutUser = new DtoOutUser();
                    mapper.Map(u, dtoOutUser);

                    dtoOutUser.TokenString = TokenTools.CreateToken(u, deviceName).TokenString;
                    return(dtoOutUser);
                }
                else
                {
                    DtoOutError error = new DtoOutError();
                    error.Exception = new DuplicateObjectInDatabaseException("User");
                    error.Message   = "This user is already created";
                    return(error);
                }
            }
            catch (Exception ex)
            {
                DtoOutError error = new DtoOutError();
                error.Exception = ex;
                error.Message   = ex.Message;
                return(error);
            }
        }
示例#3
0
        public IDtoOutObjects ChangePassword(DtoInChangePassword dtoInChangePassword)
        {
            DtoOutError error = new DtoOutError();

            if (TokenTools.Authentication(dtoInChangePassword.Token, dtoInChangePassword.DeviceName))
            {
                User       user       = TokenTools.getUserFromToken(dtoInChangePassword.Token);
                Credential credential = _credentialsRepository.FindBy(x => x.IdUser == user.Id && x.IsDeleted == false && x.ObjectUser.IsDeleted == false).FirstOrDefault(); // toto zanmená že každý user může mít jen jedny credentials
                credential.Password = dtoInChangePassword.Password;
                _credentialsRepository.Edit(credential);
                _credentialsRepository.Save();
                DtoOutComplete dtoOutComplete = new DtoOutComplete();
                dtoOutComplete.Completed = true;
                return(dtoOutComplete);
            }
            else
            {
                NotAuthenticatedException ex = new NotAuthenticatedException();
                error.Exception = ex;
                return(error);
            }
        }