예제 #1
0
        public async Task CreateNew(UserCreationProperties properties)
        {
            var user = await this.UserFactory.CreateAsync(properties.Seed, properties.Name);

            SecureStorage.StoreUser(user, properties.Password);
            SetCurrentUser(user);
        }
예제 #2
0
        /// <summary>
        /// Return a new created user object, which is saved in the database.
        /// </summary>
        /// <param name="properties"></param>
        /// <returns></returns>
        public async Task <bool> CreateNew(UserCreationProperties properties)
        {
            try
            {
                // Create the entry for secure storage to safe the encryption key for the user data.
                var salt          = Seed.Random().Value;
                var encryptionKey = new EncryptionKey(properties.Password, salt);

                var user = await this._userFactory.CreateAsync(properties.Seed, properties.Name, properties.ImagePath, properties.ImageBase64, encryptionKey);

                // Set the database service for usage.
                AppBase.Database = new DatabaseService(DependencyService.Get <ISqlite>(), encryptionKey);

                // Save user in the database.
                var result = AppBase.Database.User.AddObject(user);

                if (result == null)
                {
                    return(false);
                }

                var jsonString = JsonConvert.SerializeObject(new { userid = result.Id, salt = Convert.ToBase64String(Encoding.UTF8.GetBytes(salt)) });
                await SecureStorage.SetAsync(properties.Password, jsonString);

                this.SetCurrentUser(result);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }