Example #1
0
        public IHttpActionResult GetTraderByTraderId(string traderId)
        {
            ApplicationUser user = db.Users.Find(traderId);

            if (user == null)
            {
                ModelState.AddModelError("Message", "Trader not found!");
                return(BadRequest(ModelState));
            }

            try
            {
                ApplicationUserListDTO trddto = new ApplicationUserListDTO();
                trddto.traderId       = user.Id;
                trddto.username       = user.UserName;
                trddto.email          = user.Email;
                trddto.emailconfirmed = user.EmailConfirmed;
                trddto.passwordhash   = user.PasswordHash;

                return(Ok(trddto));
            }
            catch (Exception exc)
            {
                // TODO come up with loggin solution here
                string mess = exc.Message;
                ModelState.AddModelError("Message", "An unexpected error has occured during getting the trader details!");
                return(BadRequest(ModelState));
            }
        }
Example #2
0
        public IHttpActionResult GetTraders()
        {
            IQueryable <ApplicationUser>  allusers = db.Users;
            List <ApplicationUserListDTO> traders  = new List <ApplicationUserListDTO>();

            try
            {
                if (allusers != null)
                {
                    foreach (ApplicationUser user in allusers)
                    {
                        if (UserManager.IsInRole(user.Id, "Trader"))
                        {
                            ApplicationUserListDTO trddto = new ApplicationUserListDTO();

                            trddto.traderId       = user.Id;
                            trddto.username       = user.UserName;
                            trddto.email          = user.Email;
                            trddto.emailconfirmed = user.EmailConfirmed;
                            trddto.passwordhash   = user.PasswordHash;
                            traders.Add(trddto);
                        }
                    }
                }
                return(Ok <List <ApplicationUserListDTO> >(traders));
            }
            catch (Exception exc)
            {
                // TODO come up with loggin solution here
                string mess = exc.Message;
                ModelState.AddModelError("Message", "An unexpected error has occured during getting all traders!");
                return(BadRequest(ModelState));
            }
        }
Example #3
0
        public async Task <IHttpActionResult> ResetPassword(ResetPasswordBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("Message", "The data provided is invalid!");
                return(BadRequest(ModelState));
            }
            var user = await UserManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                ModelState.AddModelError("Message", "User can not be found!");
                return(BadRequest(ModelState));
            }

            var result = await UserManager.VerifyUserTokenAsync(user.Id, "ResetPassword", model.Code);

            if (result)
            {
                // add record in the forgot password table count
                ForgotPassword newRecord = new ForgotPassword();
                newRecord.userId        = user.Id;
                newRecord.createdDt     = DateTime.Now.ToLocalTime();
                newRecord.attemptsCount = 1;
                await fpctr.PostForgotPassword(newRecord);

                var resultPassword = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.NewPassword);

                if (resultPassword.Succeeded)
                {
                    ApplicationUserListDTO trader = new ApplicationUserListDTO();
                    trader = ((OkNegotiatedContentResult <ApplicationUserListDTO>)GetTraderByTraderId(user.Id)).Content;
                    return(Ok <ApplicationUserListDTO>(trader));
                }
                else
                {
                    ModelState.AddModelError("Message", "Error saving your new password. Please contact the application admin!");
                    return(BadRequest(ModelState));
                }
            }
            else
            {
                ModelState.AddModelError("Message", "Invalid code!");
                return(BadRequest(ModelState));
            }
        }
Example #4
0
        public async Task <IHttpActionResult> ChangePassword(ChangePasswordBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("Message", "The data provided is invalid!");
                return(BadRequest(ModelState));
            }


            IdentityResult result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

            if (!result.Succeeded)
            {
                ModelState.AddModelError("Message", "The old password is invalid!");
                return(BadRequest(ModelState));
            }

            // if all good
            ApplicationUserListDTO trader = new ApplicationUserListDTO();

            trader = ((OkNegotiatedContentResult <ApplicationUserListDTO>)GetTraderByTraderId(User.Identity.GetUserId())).Content;
            return(Ok <ApplicationUserListDTO>(trader));
        }