assign role and access group to new registered user

I would like to know whether we can assign specific(not admin roles & group) roles and group while user registration through code without changing GroupId and Default Role Id.

Thanks in advance.

Here is the simple example of user registration. Take a closer look at the RegisterScreen controller.


Thanks for reply.
I am working on user-registration project only.
I have created a Access Group = “UserGrp” and Role = "UserRole"
Now, my question is that how can I assign these roles & group to the new User through controller.

Have you tried to overview code of the RegisterScreen controller from my sample project? The required functionality is implemented within onOkBtnClick() method.