Example #1
0
        public ApplicationUser RegisterUser(string email, string password, string mobile, string lastName, string firstName)
        {
            email = email.ToLower();

            if (!IsEmailUnique(email))
            {
                throw new PropertyNotUniqueException("Email",email);
            }

            try
            {
                
                DatabaseService.BeginTransaction();
                var salt = StringHelper.GenerateSalt();
                var hash = StringHelper.GetHash(password, salt, MD5.Create());

                var user = new ApplicationUser
                {
                    UserName = email,
                    //LastName = lastName.ToTitleCase(),
                    //FirstName = firstName.ToTitleCase(),
                    //Mobile = mobile,
                    //Salt = salt,
                    //Hash = hash,
                    Active = true,
                };

                var challenge = new UserChallenge(StringHelper.GenerateSalt(64));
                user.UserChallenge = challenge;

                var wallet = new Wallet();
                DatabaseService.Save(user);
                wallet.User = user;
                DatabaseService.Save(wallet);

                DatabaseService.CommitTransaction();
                return user;
            }
            catch (System.Exception)
            {
                DatabaseService.RollBackTransaction();
                throw;
            }
        }
Example #2
0
        public void CreateAddress(ApplicationUser user, Address newAddress)
        {
            //var theUser = DatabaseService.Get<User>(user.Id);
            //if (theUser != null)
            //{
            //    theUser.Address = ((AddressService) _addressService).CreateAddress(newAddress);
            //    DatabaseService.Save(theUser);
            //}
            //else
            //{
            //    throw new EntityNotFoundException<User>(user);
            //}

        }
Example #3
0
        public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var info = await Authentication.GetExternalLoginInfoAsync();
            if (info == null)
            {
                return InternalServerError();
            }

            var user = new ApplicationUser() { UserName = model.Email };

            IdentityResult result = await UserManager.CreateAsync(user);
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            result = await UserManager.AddLoginAsync(user.Id, info.Login);
            if (!result.Succeeded)
            {
                return GetErrorResult(result); 
            }
            return Ok();
        }
Example #4
0
 void IUserService.CreateAddress(ApplicationUser user, Address newAddress)
 {
     SingleTransactionAction(CreateAddress, user, newAddress);
 }
Example #5
0
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var exist = await UserManager.FindByNameAsync(model.Email);
            if (exist == null)
            {
                var user = new ApplicationUser
                {
                    UserName = model.Email,
                    
                    UserChallenge = new UserChallenge(StringHelper.GetRandomString(ConfigurationManagerHelper.GetIntSetting("UserChallengeLength"))),
                };

                IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                if (!result.Succeeded)
                {
                    return GetErrorResult(result);
                }

                result = await UserManager.AddToRoleAsync(user.Id, IdentityRole.User.Name);

                if (!result.Succeeded)
                {
                    return GetErrorResult(result);
                }

                return Ok();
            }


            return BadRequest("User already exist");

        }